home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!noiro.acs.uci.edu!nntpsrv
- From: cedman@714-725-3165.nts.uci.edu (Carl Edman)
- Subject: Re: GNU bash shell -- how to do csh alias things in bash functions
- Nntp-Posting-Host: 714-725-3165.nts.uci.edu
- Message-ID: <2A706E75.26709@noiro.acs.uci.edu>
- Newsgroups: comp.unix.shell
- Reply-To: cedman@golem.ps.uci.edu (Carl Edman)
- Lines: 55
- Date: 24 Jul 92 20:56:21 GMT
- References: <1992Jul24.195840.11711@news.weeg.uiowa.edu>
-
- David Keber writes
- > Specifically, I have two directory related aliases in csh like this:
- >
- > alias dir='ls -aFglNqsT \!* | more'
- > alias ls='ls -CFq \!* | more'
- >
- > My understanding is that you cannot put command line arguments into
- > bash aliases (right?), so I wrote the following two bash functions:
- >
- > dir () { ls -aFglNqsT $1 | more ; }
- > ls () { ls -CFq $1 | more ; }
- >
-
- The problem with these functions is the ls function. When you type
- 'ls' the 'ls' function is executed. But during the execution of this
- function you call 'ls' again. Bash will take this to mean the 'ls'
- function, nor the external 'ls' command. So the 'ls' function gets
- called again ad infinitum, or until process slots run out. Change
- these definitions so that it is clear that you are refering to the ls
- program eg. like this.
-
- dir () { /bin/ls -aFglNqsT $1 | more ; }
- ls () { /bin/ls -CFq $1 | more ; }
-
- >
- > Another question I had was in converting the following alias:
- >
- > alias whereis "find ~ -name '\!*' -print | more"
- >
- > the function I wrote was:
- >
- > whereis() { find ~ -name $1 -print | more }
- >
- > For some reason, this function won't work with the single quotes just
- > after the -name option and before the -print function (why?). As it
- > is now, it just works unreliably. In csh, this is supposed to give a
- > list of all files matching a specific pattern, for example
- >
- > whereis *.ps
- >
- > would list the full pathname of any file that ended in ".ps".
-
- The problem here is command line expanasion. The shell will expand
- *.ps to the names of all ps files in the current directory and then
- pass that argument list to whereis. Whereis will then just take the
- first of that list and try to find that (as you used $1). Try calling
- whereis like this to avoid premature expansion.
-
- whereis '*.ps'
-
- Some shells (like zsh) also include a noglob directive which prevents
- wildcard expansion for some functions. Check you bash doc on this.
-
- Carl Edman
-
-