1846203 Members
4005 Online
110255 Solutions
New Discussion

Re: Shell Script help.

 
SOLVED
Go to solution
rmueller58
Valued Contributor

Shell Script help.

To the group.. I am trying to write a menu that a user can setup a database name variable with, without doing the
VARIABLE=variable;export VARIABLE everytime.

I wrote a script that I would assume would work, however when I echo the variable back the value is unset. I would appreciate anyone that might be able to see my mistake..

# SCRIPT BEGINS HERE..

clear
echo '

which database would you like to use:

a.) Elkhorn
b.) Ralston
c.) Papillion / LaVista
d.) Westside
e.) Arlington
f.) Blair
g.) Conestoga
h.) Ft Calhoun
i.) Gretna
j.) Valley
k.) Papillion/LaVista K
l.) Westside Foundation
m.) Millard
n.) ESU
Please select from one of the above: \c'
read choice
echo


case "$choice" in

a)export PEIDBNAME=elkfin;;
b)export PEIDBNAME=ralfin;;
c)export PEIDBNAME=plvfin;;
d)export PEIDBNAME=wstfin;;
e)export PEIDBNAME=alrfin;;
f)export PEIDBNAME=blrfin;;
g)export PEIDBNAME=confin;;
h)export PEIDBNAME=ftcfin;;
i)export PEIDBNAME=grtfin;;
j)export PEIDBNAME=valfin;;
k)export PEIDBNAME=plkfin;;
l)export PEIDBNAME=wsffin;;
m)export PEIDBNAME=mpsfin;;
n)export PEIDBNAME=esufin;;
esac



3 REPLIES 3
Patrick Wallek
Honored Contributor
Solution

Re: Shell Script help.

If you just run the script (./scriptname) then the variable will not be exported globally for that user.

What you have to do is do a '. scriptname' (there is a space between the . and the scriptname) or a 'source scriptname' depending on which shell you are using. Doing this will make it so that the variable is exported to the users shell. You can then do an 'echo $PEIDBNAME' and it should return the appropriate value.
Joseph C. Denman
Honored Contributor

Re: Shell Script help.

Patric is correct. Run the script is a . in front.

ie....

../striptname
If I had only read the instructions first??
Rodney Hills
Honored Contributor

Re: Shell Script help.

You could use alias in .profile to simplify
alias setdb=". ./scriptfile"

Then the user only enters
setdb
There be dragons...