Why use shell scripts?

If you are not already using shell scripts as part of your daily life, you are probably expending too much energy on little tasks! Shell scripts are a great way to automate repetitive tasks, receive and process user input, and create basic applications.

Using PHP to build your shell scripts allows you to not only take advantage of the power and flexibility inherent to the language, but it also brings you one more step closer to the magical day when you can type "rm /usr/bin/perl" and not worry about the repercussions!

PHP-CLI can also be used as part of a daisy-chain between other commands. For example: php -f foo.php | sort -u > myfile.txt. In my experience, slotting PHP into my existing toolkit in this way has been the most profitable use - once PHP is up there with sort , grep , and strings in terms of common use, you know you are on the right track!


Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: CLI SAPI differences >>

Previous chapter: Command-line scripting

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.