TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:2020] bash and variables



> I use bash and I'd like to use a variable to be used in a few different
> programs. I can't the variable to be defined on different tty's.
> 
> If I run
> 
> something=test
> 
> echo $something
> 
> prints test only on the tty that I ran something=test.
> 
> I've tried the export command in a script file, but that doesn't work
> either. I'm sure there is a easy command I need to do a global export, I
> just don't know what it is.

Do you want to set up a variable that doesn't change?  Like adding
something to the PATH variable?  If so, I'd recommend putting stuff like
that in your /etc/profile file...  (or one of the related ones..)

Anyway, it all comes down to inheritance..  If you start bash while in
bash, the new bash will contain all of the variables that were in the
'parent' bash..

The reason that the other ttys don't have the variable in them is
because the shells on those ttys haven't inherited from the other shell
where you set the variable.

Hmm.. I'm not sure if that helps (I'm kinda known for being cryptic, eh?
;-)

Also, if you want to get variables out of a file and set in your current
shell (running a script with a bunch of 'export' lines doesn't work,
since they only affect the shell they're running in -- the script
itself...)

run 'source <filename>'  (I think...)

Looks like '. <filename>' is equivalent...

The file would just be a bunch of lines like this

VAR1=value1
VAR2=value2

Hope that helps...

-- 
                    --== Mike Hicks ==--
http://umn.edu/~hick0088	mailto:hick0088@tc.umn.edu
                        ICQ:6883760
Linux User Since 1.2.13            Current Kernel: 2.1.125