I am writing a central script, which acts as a menu driven cli through which I trigger other scripts based on the input.
#!/bin/bash
echo "Server Name - `hostname`"
echo "-------------------------------"
echo " M A I N - M E N U"
echo "-------------------------------"
echo "1. init"
echo "2. insert"
echo "3. show"
echo "4. update"
echo "5. rm"
echo "6. ls"
echo "7. shutdown -> shutdown the server"
while :
do
printf '> '
read -r varname
set -- $varname
case $1 in
init)
./init.sh $2
echo $status
;;
insert)
./insert.sh $2 $3 '' $4
;;
show)
./show.sh $2 $3
;;
update)
./insert.sh $2 $3 'f' $4
;;
rm)
./rm.sh $2 $3
;;
ls)
./ls.sh $2 $3
;;
shutdown)
exit 0
;;
exit)
exit 0
;;
*)
#echo "Error: Bad request"
;;
esac
done
Current:
I have purposefully added the print '> ' statement so as to get an interactive interface just like node cli.
insert user1 google 'login:blahblah@gmail.com\npass:blah'
- $1 is insert
- $2 is user1
- $3 is google
- $4 is 'login:blahblah@gmail.com\npass:blah'
Expected:
I wish to read arguments the same way we pass arguments when we run a script.
Ex:
sh add.sh 10 20 or sh add.sh "10" "20"
Either way when we read $1 or $2 in the add shell script, we will be getting 10 and 20 as their values.
insert user1 google 'login:blahblah@gmail.com\npass:blah'
- $1 is insert
- $2 is user1
- $3 is google
- $4 is login:blahblah@gmail.com\npass:blah
I do not want to get the input and then remove the trailing quotes. I would like to have the exact behaviour when we run a script and pass arguments.
PS: Please suggest how to get a cli just like node too which has access to previously run commands using the Up arrow.
Thanks in advance