linux - Why isn't export working from bash script -
why isn't exporting variable working in following case:
in following example export param variable , set sleep 1000 second in order run script process on background.
#!/bin/bash export param="i real value" sleep 1000 so execute script process following:
/tmp/example.bash & now script runs process (i checked ps -ef) , linux console want print $param following
echo $param but no value param variable.
why? export script isn’t exporting value when script process running.
when run /tmp/example.bash &, set environment in sub-shell, not affect parent shell ran it.
you need (a) remove sleep 1000 , (b) use . command or (in bash or c shell) source command read file part of current process:
sed -i.bak '/sleep/d' /tmp/example.bash # gnu or bsd sed . /tmp/example.bash echo $param
Comments
Post a Comment