Skip to Content
Shell Scripting: Expert Recipes for Linux, Bash, and More
book

Shell Scripting: Expert Recipes for Linux, Bash, and More

by Steve Parker
August 2011
Beginner to intermediate
600 pages
14h 29m
English
Wrox
Content preview from Shell Scripting: Expert Recipes for Linux, Bash, and More

Preset and Standard Variables

There are a few variables which are provided by the shell itself. These vary in nature quite a bit: Some of them are purely informational, such as $BASH_VERSION, which tells you the version of bash that you are running (for example, 4.1.5(1)-release), but which you can override simply by setting them. Others return a different value depending on the current environment, such as $PIPESTATUS, which tells you the return codes of the commands in the last-run pipeline, and still others return a different value depending on some function of their own (such as $SECONDS, an integer which goes up by one every second). Also, some of these variables lose their special meaning if you set (or unset) them: $RANDOM will keep returning random numbers until you assign it a value, after which it will not produce random numbers again. $SECONDS will always keep counting; if you set SECONDS=35 and then read $SECONDS again 5 seconds later, it will have counted up to 40. Still others are not writeable at all; you will get an error message if you try setting UID, for instance. There are yet others, like TIMEFORMAT, which do nothing by themselves, but are used to affect how other commands work.

The following examples include some of the more common and useful predefined variables, as well as some that are less well known.

BASH_ENV

BASH_ENV is the name of a file (which may be a relative path, in which case be very careful about where you run your scripts from!) which is parsed ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Command Line and Shell Scripting Techniques

Linux Command Line and Shell Scripting Techniques

Vedran Dakic, Jasmin Redzepagic
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781118166321Purchase bookDownloads