home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / shell / 3128 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  2.4 KB

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