O'Reilly logo

Wicked Cool Shell Scripts, 2nd Edition by Brandon Perry, Dave Taylor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2IMPROVING ON USER COMMANDS

image

A typical Unix or Linux system includes hundreds of commands by default, which, when you factor in flags and the possible ways to combine commands with pipes, produces millions of different ways to work on the command line.

Before we go any further, Listing 2-1 shows a bonus script that will tell you how many commands are in your PATH.

#!/bin/bash # How many commands: a simple script to count how many executable # commands are in your current PATH IFS=":" count=0 ; nonex=0 for directory in $PATH ; do if [ -d "$directory" ] ; then for command in "$directory"/* ; do if [ -x "$command" ] ; then count="$(( $count + 1 ))" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required