Aliases and Variables Keep Things Short and Simple
![]() |
Note: You can set up the commands given below either directly from the command line or by putting them into your shell config file (e.g., ~/.bashrc or ~/.tcshrc) and then sourcing that.
Occasionally, I want to check which desktop belongs to a particular user. I have a local LDAP directory value set for this, so the command
ldapsearch "(localUser=username)"does the trick. I want to set up an alias for this, with the command line argument taking the place of username.
In tcsh, this can be done straightforwardly using !:1 for the first argument, !:2 for the second, and so on. Remember, you'll need to escape the ! in the alias definition.
So for my LDAP search:
alias finduser 'ldapsearch "(localUser=!:1)"' |
$ finduser username |
Unfortunately, in bash/sh/ksh this is no good, as you can't put arguments in aliases. What you can do to produce the same effect is write a function.
function finduser() { ldapsearch "(localUser=$1)"; } |
To pass in further arguments to bash, you use $2, $3 and so on. Or, to pass in all the arguments on the command line, $*. This gives much more scop for saving your typing fingers!
- 1 Linux Server Management Nightmare: Attack of the Killer Penguins
- 2 Top 10 Open-Source Server Technologies You Need to Know
- 3 10 Coolest Features in Windows Server 2008
- 4 Getting Started With EFT Server -- A More Secure FTP Server Option
- 5 Making Linux Server Directories More Readable, Add to Perl's @INC Array




Windows Server 2008 R2 provides enhanced management control over resources across the enterprise. Downlaod this PDF to learn more.