I can succeed to grab the environment variable in command line.
But if I put the commands in a .sh file, then run the .sh file.
Nothing is printed. Any reason ?
root@mydesktop:/tmp$ s1="hello stackoverflow"
root@mydesktop:/tmp$ echo $s1
hello stackoverflow
root@mydesktop:/tmp$/tmp$ set | grep s1
s1='hello stackoverflow'
--> it's good to show as expect, then I save those commands to a script file test.sh
#!/bin/sh
echo $s1
echo ${s1}
hello=$( set | grep s1 )
echo $hello
echo ${hello}
But after script run, I don't get the expected result
root@mydesktop:/tmp$ ./test.sh
root@mydesktop:/tmp$
Any idea ?
Update:
OK , found strange thing:
#set
s1=' balaba '
'
s2='another string'
the is one more ' --> it could be the root cause.
echo $BASH_VERSIONsay?export s1="foo bar"