Need help with a basic shell script

Carobthomp

Honorable
Nov 12, 2013
204
0
10,760
40
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
 
Oh, I agree with that.

Basically I don't see the point in what the OP is trying to achieve. If you are more comfortable with Windows commands than Unix ones then just use Wndows. If you can't be bothered to learn the Unix commands why bother with the OS?

And if you really do want to write your own shell, for whatever reason, use C not shell scripts.
 

Carobthomp

Honorable
Nov 12, 2013
204
0
10,760
40
It's not that I'm more comfortable with windows commands, it was just an example for an assignment.

If I preferred windows commands, I would definitely use alias.

I was able to figure it out, by adding:

*)
$reply1 $reply2
;;

Thank's for all the advice, and sorry about the confusion.
 
Thread starter Similar threads Forum Replies Date
nukesnicks Open Source 7

Similar threads


ASK THE COMMUNITY

TRENDING THREADS