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

34.8. Security Issues<br />

A brief warning about script security is appropriate. A shell script may contain a worm, trojan, or even a<br />

virus. For that reason, never run as root a script (or permit it to be inserted into the system startup scripts in<br />

/etc/rc.d) unless you have obtained said script from a trusted source or you have carefully analyzed it to<br />

make certain it does nothing harmful.<br />

Various researchers at Bell Labs and other sites, including M. Douglas McIlroy, Tom Duff, and Fred Cohen<br />

have investigated the implications of shell script viruses. They conclude that it is all to easy for even a novice,<br />

a "script kiddie", to write one. [65]<br />

Here is yet another reason to learn scripting. Being able to look at and understand scripts may protect your<br />

system from being hacked or damaged.<br />

34.9. Portability Issues<br />

This book deals specifically with Bash scripting on a GNU/Linux system. All the same, users of sh and ksh<br />

will find much of value here.<br />

As it happens, many of the various shells and scripting languages seem to be converging toward the POSIX<br />

1003.2 standard. Invoking Bash with the −−posix option or inserting a set −o posix at the head of a script<br />

causes Bash to conform very closely to this standard. Even lacking this measure, most Bash scripts will run<br />

as−is under ksh, and vice−versa, since Chet Ramey has been busily porting ksh features to the latest versions<br />

of Bash.<br />

On a commercial UNIX machine, scripts using GNU−specific features of standard commands may not work.<br />

This has become less of a problem in the last few years, as the GNU utilities have pretty much displaced their<br />

proprietary counterparts even on "big−iron" UNIX. Caldera's release of the source to many of the original<br />

UNIX utilities will only accelerate the trend.<br />

Bash has certain features that the traditional Bourne shell lacks. Among these are:<br />

• Certain extended invocation options<br />

• Command substitution using $( ) notation<br />

• Certain string manipulation operations<br />

• Process substitution<br />

• Bash−specific builtins<br />

See the Bash F.A.Q. for a complete listing.<br />

34.10. Shell Scripting Under Windows<br />

Even users running that other OS can run UNIX−like shell scripts, and therefore benefit from many of the<br />

lessons of this book. The Cygwin package from Cygnus and the MKS utilities from Mortice Kern Associates<br />

add shell scripting capabilities to Windows.<br />

Chapter 34. Miscellany 354

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

Saved successfully!

Ooh no, something went wrong!