home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 16.14 Showing Non-Printable Characters in Filenames Chapter 16
Where Did I Put That?
Next: 16.16 Picking a Unique Filename Automatically
 

16.15 Script with a :-) for UNIX Converts: dir, ..., ...

I've switched back and forth between UNIX, VMS, MS/DOS, and other OSes. Others use DIR to do what ls does on UNIX. I wrote a script that saves me retyping a command and gives me a grin, too:

% dir


Hey!  This is UNIX!  Well, okay... but just this once...
total 265
-rw-rw-r--  1 ellie       47279 Dec 16 13:22 2edit.2
-rw-r--r--  1 jerry       21802 Nov 12 18:24 7911.ps
drwxrwsr-x  2 jerry       14848 Dec 24 07:17 RCS

hey
The Bourne shell script, named hey , is simple. It prints its complaint to standard error so the message won't be redirected into a file or down a pipe. Then it tests the name you called it with (in this case, dir ) and runs the command you've configured it to run instead (here, ls -l ):


$@
 



case "$0" in

*dir) ls -l ${1+"$@"} ;;
*md)  mkdir ${1+"$@"} ;;
   ...and so on...

esac

You can give the single hey script file as many names as you want by making links (18.3 ) to it. Article 8.8 shows a similar setup with a different purpose.

- JP


Previous: 16.14 Showing Non-Printable Characters in Filenames UNIX Power Tools Next: 16.16 Picking a Unique Filename Automatically
16.14 Showing Non-Printable Characters in Filenames Book Index 16.16 Picking a Unique Filename Automatically

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System