O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.2. Local variables

Local variables are what you would use in a script for your current shell lifetime, then discard. For instance, a local variable called file_name may have the value loops.doc. This value is important to you but only for the lifetime of your current shell; you do not keep that value if you start another process in your shell or log out. This is good news because you cannot make this type of variable available to other shells or processes.

Table 14.1 contains various variable modes of action.

When using variables some users like to enclose them in curly brackets, which stops the shell from misinterpreting the value of the variable. You do not have to, but this can be useful.

To assign a local variable the format is:

$variable_name=value ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required