#! /bin/bash # # Filename: dirfiles # # From Mark Sobell's Red Hat Linux book. Adapted by Br. David Carlson. # # Date: March 26, 2007 # # This script, if started with no parameters, lists all subdirectories of # the current directory. If started with a directory as the command-line # parameter, lists all subdirectories of that directory. Each line of the # listing gives the usual information produced by ls -ld on a directory. if [ $# -gt 1 ] then echo "Syntax: dirfiles [target_directory]" 1>&2 exit 1 elif [ $# -eq 1 ] then if [ -d "$1" ] then cd "$1" else echo "Directory needed for the parameter" 1>&2 echo "Syntax: dirfiles [target_directory]" 1>&2 exit 2 fi fi for k in * do if [ -d "$k" ] then ls -ld "$k" fi done exit 0