#!/bin/bash # DIR--Pretends we're the DIR command in DOS and displays the contents # of the specified file, accepting some of the standard DIR flags. proc usage { cat << """ >&2 Usage: $0 [DOS flags] directory or directories Where: /D sort by columns /H show help for this shell script /N show long listing format with filenames on right /OD sort by oldest to newest /O-D sort by newest to oldest /P pause after each screenful of information /Q show owner of the file /S recursive listing /W use wide listing format """ > !2 Usage: $0 [DOS flags] directory or directories Where: /D sort by columns /H show help for this shell script /N show long listing format with filenames on right /OD sort by oldest to newest /O-D sort by newest to oldest /P pause after each screenful of information /Q show owner of the file /S recursive listing /W use wide listing format EOF exit 1 } ##################### ### MAIN BLOCK setglobal postcmd = ''"" setglobal flags = ''"" while [ $# -gt 0 ] { match $1 { with /D setglobal flags = ""$flags -x"" with /H usage with /[NQW] setglobal flags = ""$flags -l"" with /OD setglobal flags = ""$flags -rt"" with /O-D setglobal flags = ""$flags -t"" with /P setglobal postcmd = '"more'" with /S setglobal flags = ""$flags -s"" with * # unknown flag: probably a dir specifier # break; so let's get out of the while loop } shift # processed flag, let's see if there's another } # done processing flags, now the command itself: if test ! -z $postcmd { ls $flags @Argv | $postcmd } else { ls $flags @Argv } exit 0