27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

(Thanks, S. C., for clarification and examples.)<br />

$IGNOREEOF<br />

ignore EOF: how many end−of−files (control−D) the shell will ignore before logging out.<br />

$LC_COLLATE<br />

Often set in the .bashrc or /etc/profile files, this variable controls collation order in filename<br />

expansion and pattern matching. If mishandled, LC_COLLATE can cause unexpected results in<br />

filename globbing.<br />

As of version 2.05 of Bash, filename globbing no longer distinguishes between<br />

lowercase and uppercase letters in a character range between brackets. For example, ls<br />

[A−M]* would match both File1.txt and file1.txt. To revert to the<br />

customary behavior of bracket matching, set LC_COLLATE to C by an export<br />

LC_COLLATE=C in /etc/profile and/or ~/.bashrc.<br />

$LC_CTYPE<br />

This internal variable controls character interpretation in globbing and pattern matching.<br />

$LINENO<br />

This variable is the line number of the shell script in which this variable appears. It has significance<br />

only within the script in which it appears, and is chiefly useful for debugging purposes.<br />

# *** BEGIN DEBUG BLOCK ***<br />

last_cmd_arg=$_ # Save it.<br />

echo "At line number $LINENO, variable \"v1\" = $v1"<br />

echo "Last command argument processed = $last_cmd_arg"<br />

# *** END DEBUG BLOCK ***<br />

$MACHTYPE<br />

machine type<br />

Identifies the system hardware.<br />

bash$ echo $MACHTYPE<br />

i686<br />

$OLDPWD<br />

old working directory ("OLD−print−working−directory", previous directory you were in)<br />

$OSTYPE<br />

operating system type<br />

bash$ echo $OSTYPE<br />

linux<br />

$PATH<br />

path to binaries, usually /usr/bin/, /usr/X11R6/bin/, /usr/local/bin, etc.<br />

When given a command, the shell automatically does a hash table search on the directories listed in<br />

the path for the executable. The path is stored in the environmental variable, $PATH, a list of<br />

directories, separated by colons. Normally, the system stores the $PATH definition in<br />

/etc/profile and/or ~/.bashrc (see Chapter 27).<br />

bash$ echo $PATH<br />

/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/sbin:/usr/sbin<br />

PATH=${PATH}:/opt/bin appends the /opt/bin directory to the current path. In a script, it<br />

may be expedient to temporarily add a directory to the path in this way. When the script exits, this<br />

Chapter 9. Variables Revisited 67

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!