When I run the 'set' command in a bash shell, I see a variable has a value. However, when I run the 'set' command in a bash script, the variable does not exist. Why? How might I make this happen?
AxOS(7iq1) root:/mnt/ax/scratch/roshi# set
--snip--
SERIAL_NUMBER=7iq1
--snip--
AxOS(7iq1) root:/mnt/ax/scratch/roshi#
My shell script tmp.sh contains
#!/bin/bash
svcid=`set | grep ^SERIAL_NUMBER | awk '{ split($1,a,"=");print a[2] }'`
echo ${svcid}
If I execute the script as follows, I get no output
AxOS(7iq1) root:/mnt/ax/scratch/roshi# ./tmp.sh
AxOS(7iq1) root:/mnt/ax/scratch/roshi#
If I execute the script as (first suggested by Doon)
AxOS(7iq1) root:/mnt/ax/scratch/roshi# . ./tmp.sh
7iq1
AxOS(7iq1) root:/mnt/ax/scratch/roshi#
. script.shand it will run in the current shell. does that fix the issue? else as @Useless said, example pleasesvcid=$SERIAL_NUMBERthat I have ever seen.