24.07.2018 Views

Bash-Beginners-Guide

Create successful ePaper yourself

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

<strong>Bash</strong> <strong>Guide</strong> for <strong>Beginners</strong><br />

/dev/hda5<br />

5.2G 4.3G 725M 86% /var<br />

franky ~> unalias dh<br />

franky ~> dh<br />

bash: dh: command not found<br />

franky ~><br />

<strong>Bash</strong> always reads at least one complete line of input before executing any of the commands on that line.<br />

Aliases are expanded when a command is read, not when it is executed. Therefore, an alias definition<br />

appearing on the same line as another command does not take effect until the next line of input is read. The<br />

commands following the alias definition on that line are not affected by the new alias. This behavior is also an<br />

issue when functions are executed. Aliases are expanded when a function definition is read, not when the<br />

function is executed, because a function definition is itself a compound command. As a consequence, aliases<br />

defined in a function are not available until after that function is executed. To be safe, always put alias<br />

definitions on a separate line, and do not use alias in compound commands.<br />

Aliases are not inherited by child processes. Bourne shell (sh) does not recognize aliases.<br />

More about functions is in Chapter 11.<br />

Functions are faster<br />

Aliases are looked up after functions and thus resolving is slower. While aliases are easier to understand,<br />

shell functions are preferred over aliases for almost every purpose.<br />

3.6. More <strong>Bash</strong> options<br />

3.6.1. Displaying options<br />

We already discussed a couple of <strong>Bash</strong> options that are useful for debugging your scripts. In this section, we<br />

will take a more in-depth view of the <strong>Bash</strong> options.<br />

Use the -o option to set to display all shell options:<br />

willy:~> set -o<br />

allexport<br />

braceexpand<br />

emacs<br />

errexit<br />

hashall<br />

histexpand<br />

history<br />

ignoreeof<br />

interactive-comments<br />

keyword<br />

monitor<br />

noclobber<br />

noexec<br />

noglob<br />

nolog<br />

notify<br />

nounset<br />

onecmd<br />

physical<br />

off<br />

on<br />

on<br />

off<br />

on<br />

on<br />

on<br />

off<br />

on<br />

off<br />

on<br />

off<br />

off<br />

off<br />

off<br />

off<br />

off<br />

off<br />

off<br />

Chapter 3. The <strong>Bash</strong> environment 53

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

Saved successfully!

Ooh no, something went wrong!