Trying to do some basic scripting.
The task:
Create a DOS-like shell on top of the bash shell (so that when you enter "del" it executes the "rm" command in Linux)
I've got all that working fine, my issue, is that when you type in a command that is just a regular Linux command, it should pass it to the bash shell for execution.
This is what I have so far, and again, this works fine for the 'dos-like' commands:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/bash #operating in the bash shell
stop = 0 #stop has a value of 0
while [ stop -eq 0 ] #loop when stop is equal to 0
do #start loop
echo - n $HOME\> #prompt is set to home variable
read reply1 reply2 reply3 #read variables for first, second, and third reply.
case $reply1 in
"cd") #when user types "cd", execute change directory command.
cd
;;
"del")
rm $reply2 #when user types "del", execute remove command for specified parameter.
;;
"ren")
mv $reply2 $reply3 #when user types "ren", execute the move (rename) command.
;;
"more")
ls | more #when user types "more", execute the display one screen command (ls | more).
;;
"copy")
cp $reply2 $reply3 #when user types "copy", execute the cp comand for <file> <file>
;;
"xcopy")
cp -R $reply2 $reply3 #when user types "xcopy", execute the cp command with recursive parameter.
;;
esac
done
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I'm thinking the best option would be to use an "if" statement, and have anything executable passed to the shell, but I'm not sure how to properly type it and debug it.
ie:
if [ $reply1 -x ]
then
$reply1 | /bin/bash
---------not sure what do to for the else portion?
If anybody could give me any suggestions on a way to have this work, it would be greatly appreciated!
- Carobthomp
The task:
Create a DOS-like shell on top of the bash shell (so that when you enter "del" it executes the "rm" command in Linux)
I've got all that working fine, my issue, is that when you type in a command that is just a regular Linux command, it should pass it to the bash shell for execution.
This is what I have so far, and again, this works fine for the 'dos-like' commands:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/bash #operating in the bash shell
stop = 0 #stop has a value of 0
while [ stop -eq 0 ] #loop when stop is equal to 0
do #start loop
echo - n $HOME\> #prompt is set to home variable
read reply1 reply2 reply3 #read variables for first, second, and third reply.
case $reply1 in
"cd") #when user types "cd", execute change directory command.
cd
;;
"del")
rm $reply2 #when user types "del", execute remove command for specified parameter.
;;
"ren")
mv $reply2 $reply3 #when user types "ren", execute the move (rename) command.
;;
"more")
ls | more #when user types "more", execute the display one screen command (ls | more).
;;
"copy")
cp $reply2 $reply3 #when user types "copy", execute the cp comand for <file> <file>
;;
"xcopy")
cp -R $reply2 $reply3 #when user types "xcopy", execute the cp command with recursive parameter.
;;
esac
done
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I'm thinking the best option would be to use an "if" statement, and have anything executable passed to the shell, but I'm not sure how to properly type it and debug it.
ie:
if [ $reply1 -x ]
then
$reply1 | /bin/bash
---------not sure what do to for the else portion?
If anybody could give me any suggestions on a way to have this work, it would be greatly appreciated!
- Carobthomp