Computing.Net > Forums > Unix > unix bash script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

unix bash script

Reply to Message Icon

Name: jer
Date: April 7, 2003 at 20:31:51 Pacific
OS: linux-redhat
CPU/Ram: dial into server
Comment:

I am attempting to write a script that takes positional parameter arguments and then uses them later.e.g.($ myselect.sh open read ...)
What I do next is attempt use the eval function, but I do not understand how to evaluate back to the args. listed. here's some code.
$ sh myselect.sh open read write close
PS3="Enter choice: "
x=0
choice=""

while true ; do
for i in $@ ; do
x=$(($x + 1))
echo "$x) $i" #this creates a menu list
done
echo $PS3 #diplay prompt
read choice #get user input
i=$choice #this is where it gets ugly
eval $i #I want eval to determine which
#arg. matches to choice var.
echo "$choice ...$i"
x=0
done



Sponsored Link
Ads by Google

Response Number 1
Name: jer
Date: April 8, 2003 at 03:43:54 Pacific
Reply:

I figured out what I was doing wrong. Just in case anyone might care to know.
Instead of assigning the read input to a var. named i, simply use following code to evaluate matching positional parameter #.

eval out=\$$choice

This line will match the value of the var. $choice to command line positional parameter variable.
For e.g. user inputs 2 and that will make $choice == 2
but in code above eval will assign to the var. $out the string value of $2 == read


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: unix bash script

Unix Command Script www.computing.net/answers/unix/unix-command-script/4244.html

Verify maildelivery in bash script www.computing.net/answers/unix/verify-maildelivery-in-bash-script/5565.html

Unix mail script www.computing.net/answers/unix/unix-mail-script/1201.html