currently I'm working on 2 code :
the first code is a code to display a menu to the user (start.sh) :
#!/bin/sh
echo choose a number :
echo "1.)display place information"
echo "2.)look for first character entered"
read number
case $number in
"1") ./script.sh;;
"2") ./script2.sh;;
esac
exit
the code for script.sh is :
#!/bin/sh
grep "$1" Place.txt
basically, when running script.sh , I need to enter 1 argument like ./script.sh home
and it match the word 'home' in Place.txt.
But , when i run the "start.sh" script and choose number 1 which run "script.sh" script I have nowhere to enter the argument (home) and the "script.sh" code won't run.
any suggestion how to achieve that?
start.sh:
#!/bin/sh
echo choose a number :
echo "1.)display place information"
echo "2.)look for first character entered"
read number
case $number in
"1") echo "Please input argument"; read p; ./script.sh "$p";;
"2") echo "Please input argument"; read p; ./script2.sh "$p";;
esac
exit
script.sh
#!/bin/sh
echo "Please input argument"
read p
grep "$p" Place.txt
Just dont do both.
why do you want to call another shell script when you can do it in one?
echo choose a number :
echo "1.)display place information"
echo "2.)look for first character entered"
read number
case $number in
1) read -p "Enter pattern to search: " search
grep $search file.txt
;;
2) ;;
esac
exit
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.