Apr
09
2009

How to Distinguish Environment Variables from Different Shells in “bash”?

Every instance of the command line shell (thus every process) on Unix (and hence Linux) has a different set of environment variables. Actually different shell instances you may have the same variable, but set to different values.

If you are doing a system wide job and you are using shell scripting, you would like to know whether you are referring to the same or different local environment variables. The Bourne Again SHell (bash) provides a handy syntax for that. The command line below

$ echo ${MYVAR/%/.$$}

will print the value of environment variable MYVAR with a dot and the process ID (PID) appended at the end of the value. e.g.:

$ ps
  PID TTY          TIME CMD
24768 pts/10   00:00:00 bash
25172 pts/10   00:00:00 ps
$ MYVAR=”Sample Text”
$ echo $MYVAR
Sample Text
$ echo ${MYVAR/%/.$$}
Sample Text.24768
$

Hope that helps…

Share
Written by in: linux,sysadm | Tweet This

No Comments »

RSS feed for comments on this post. TrackBack URL


Leave a Reply

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com