I need to make Bash take DOS commands in with arguments and then convert the main command to a Bash command and still use the arguments if there are any arguments.
The part I am lost on is how to pass arguments to the individual cases and not getting stuck by the *) Command Not Found!
For example a user inputs:
copy file1.txt file2.txt
Use case: copy
then should run the Linux cp
command and use the two arguments passed copy to finish the command.
#!/bin/bash
while :
do
read INPUT_STRING
case $INPUT_STRING in
chdir|CHDIR)
cd $arg1
bash myscript.sh
;;
cls|CLS)
clear
bash myscript.sh
;;
copy|COPY)
cp $arg1 $arg2
bash myscript.sh
;;
createdir|CREATEDIR)
mkdir $arg1
bash myscript.sh
;;
delete|DELETE)
rm $arg1
bash myscript.sh
;;
dir|DIR)
ls
bash myscript.sh
;;
move|MOVE)
mv $arg1 $arg2
bash myscript.sh
;;
print|PRINT)
echo $arg1
bash myscript.sh
;;
quit|QUIT)
break
PS1="n01396736@cisvm-cop4640-2:~$ "
;;
rename|RENAME)
mv $arg1 $arg2
bash myscript.sh
;;
type|TYPE)
cat $arg1
bash myscript.sh
;;
*)
echo "Command Not Found!!"
bash myscript.sh
;;
esac
break
done
bash myscript.sh
at the end of each case branch to do? I think you're trying to loop, but you're actually calling the script from itself over and over again. Remove thebreak
at the end and strip out all thesebash myscript.sh
statements. – Chris Davies Feb 14 '19 at 23:59mv $arg1 $arg2
should be rewritten asmv "$arg1" "$arg2"
) – Chris Davies Feb 15 '19 at 00:00read command arg1 arg2 arg3
case "$command" in
then I am using "$arg1" to "$arg3" as needed
– Trinity Zamrzla Feb 15 '19 at 01:37