Link to home
Start Free TrialLog in
Avatar of penguins_rule
penguins_ruleFlag for United States of America

asked on

bash script to expand variables

in a bash script, the user keys in a command with arguments
some of the arguments are variables defined in the bash profile
i need to run the command they enter
How does the script get the information and then does the whole command?

in the bash profile
  export TESTING=/home/programming

in the script, the user keys in: cd $TESTING/penguins

the script needs to: cd /home/programming/penguins

I am running RedHat EL 6.4
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

The script inherits the variables from the environment, you are setting the TESTING variable in the bash profile.

In the script you can use variables by using $VARIABLE_NAME or ${VARIABLE_NAME} in your case $TESTING or ${TESTING}

By doing: cd $TESTING/penguins in the script it is in fact doing: cd /home/programming/penguins

So looks OK to me ;)
ASKER CERTIFIED SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of penguins_rule

ASKER

in my case, i am using the script to make sure they can only type in certain commands. Otherwise, i agree, it would be dangerous.