The time now is Sat 27 Feb 2021, 06:17
All times are UTC - 4 |
Author |
Message |
kethd
Joined: 20 Oct 2005 Posts: 451 Location: Boston MA USA
|
Posted: Thu 22 Dec 2005, 09:08 Post subject:
How to pass Named Variable to script |
|
How to pass named variables to ash/bash shell scripts
If you want to test a shell script that uses named variables, with values passed in from the outside, things are somewhat confusing.
If you just set a value:
# SBUG=trying
and then run your script:
# ash testscript
you'll be surprised to find that $SBUG is null, empty.
The reason is that the value that you set exists only at that level, and your testscript ran as a nested sub-shell, one level down.
To make this work, use the export command:
# export SBUG=newval -- or just:
# export SBUG
which will make the named variable available at that level, and all nested levels below (but not at any levels above). If you change the value at any of nested levels below, the new value will be inherited by any levels below that, but levels above will retain their previous values.
You can view named variables with the set or env commands. The set command gives a nice ordered list, but it includes both "environment" variables and some kind of "other" values. The env command seems to show a more limited list, in hodge-podge order. Using these commands inside of test scripts can help you understand what values they are seeing.
(This is not the standard way to pass arguments to scripts. The normal way is with in-line positional arguments, $1 $2 $3 etc.)
|
Back to top
|
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
[ Time: 0.8140s ][ Queries: 11 (0.7761s) ][ GZIP on ] |