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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

exit 0<br />

run−parts<br />

The run−parts command [33] executes all the scripts in a target directory, sequentially in<br />

ASCII−sorted filename order. Of course, the scripts need to have execute permission.<br />

yes<br />

The crond daemon invokes run−parts to run the scripts in the /etc/cron.* directories.<br />

In its default behavior the yes command feeds a continuous string of the character y followed by a<br />

line feed to stdout. A control−c terminates the run. A different output string may be specified, as in<br />

yes different string, which would continually output different string to stdout.<br />

One might well ask the purpose of this. From the command line or in a script, the output of yes can be<br />

redirected or piped into a program expecting user input. In effect, this becomes a sort of poor man's<br />

version of expect.<br />

yes | fsck /dev/hda1 runs fsck non−interactively (careful!).<br />

yes | rm −r dirname has same effect as rm −rf dirname (careful!).<br />

Caution advised when piping yes to a potentially dangerous system command, such as<br />

fsck or fdisk. It may have unintended side−effects.<br />

banner<br />

Prints arguments as a large vertical banner to stdout, using an ASCII character (default '#'). This<br />

may be redirected to a printer for hardcopy.<br />

printenv<br />

Show all the environmental variables set for a particular user.<br />

bash$ printenv | grep HOME<br />

HOME=/home/bozo<br />

lp<br />

The lp and lpr commands send file(s) to the print queue, to be printed as hard copy. [34] These<br />

commands trace the origin of their names to the line printers of another era.<br />

bash$ lp file1.txt or bash lp

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

Saved successfully!

Ooh no, something went wrong!