0

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?

2
  • You presumably need to prompt for the word in start.sh and then pass it as an argument to script.sh. read info and ./script.sh "$info". Commented Nov 9, 2014 at 5:16
  • oh yes , that's what I was trying to achieve ! it works now. thanks ! Commented Nov 9, 2014 at 5:46

2 Answers 2

1

You can either read the input from start.sh:

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

Or do it in script.sh:

script.sh

#!/bin/sh
echo "Please input argument"
read p
grep "$p" Place.txt

Just dont do both.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.