Monday, December 16, 2013

Script value

www.unixbabuforum.inI have to define a value outside of script ex. 
./script value1 
inside is 
it seems not working 

in windows it works like that 
scrip.cmd value1 
inside is 
set v1=%1 

www.unixbabuforum.inuse instead 
v1 = $1 

and read manual on command line arguments. $1 indicates the first 
argument specified in the command. 

www.unixbabuforum.inUse this... 

www.unixbabuforum.inIf you set a variable and want it visible you should export it: 
export variable=$value 
remember that variables disappear when the shell that creates them terminates. You have to export it to preserve its value. 
Positional parameters like $1 are only valid in the script that uses it so 
This only makes sense if there was a value in the first place. Once $1 is assigned to a variable, you can export it and it will be visible to subsequent sub-shells. 
If it's a script you need to test that $1 is set before trying to use it: 
if [ "$1" != "" ] 
export $var 
echo "You need to supply an argument to $0" 
sleep 2 
exit 0 
Always use the double-quotes around your variables until you're sure they're set. Make sure there are no spaces around the = sign


Post a Comment

Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM