home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / bash / bug / 748 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  2.1 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!odin.ins.cwru.edu!chet
  2. From: chet@odin.ins.cwru.edu (Chet Ramey)
  3. Newsgroups: gnu.bash.bug
  4. Subject: Re: can't unalias
  5. Date: 21 Jan 1993 18:20:29 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 51
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-bash@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <9301211906.AA00764.SM@odin.INS.CWRU.Edu>
  12. References: <9301211836.AA20032@delta.ee.ufl.edu>
  13. Reply-To: chet@po.cwru.edu
  14.  
  15. > I pared my personal startup file down to 
  16. >     if [ "$PS1" ]; then :
  17. >         alias
  18. >         echo ====
  19. >         unalias ls
  20. >         alias
  21. >         ls () { /usr/bin/ls -aCFq "$@"; }
  22. >     fi
  23. > which fails as previously described, no output from the alias command,
  24. > just:
  25. >     bash$ bash
  26. >     syntax error near `()'
  27. >     /home/alpha/ruck/.shrc+:6: `ls () { /usr/bin/ls -aCFq "$@"; }'
  28. >     bash$ 
  29. >     
  30. > BUT when I pull that block out of the if-then by commenting out the
  31. > first and last line, I get it working fine.
  32.  
  33. There is alias expansion being performed, regardless of the presence of
  34. the `alias' and `unalias' commands.  Bash always reads a complete command,
  35. which may consist of multiple lines, before executing it.  In your case,
  36. the `if...fi' block is a complete command, and bash is attempting to read
  37. all of it and construct a command tree before executing the test or the
  38. body.
  39.  
  40. Since alias expansion is performed when a command is read, the `ls' in
  41. the above command is being expanded.  You need to put `unalias ls'
  42. before the if statement in which your function is defined.  It won't
  43. hurt to make the unalias unconditional; alias expansion is not performed
  44. when the shell is not interactive.
  45.  
  46. > OR if I leave it in the if-then as shown above, and simply insert
  47. > "function" in front of the function def, like 
  48. >         function ls () { /usr/bin/ls -aCFq "$@"; }
  49.  
  50. This works because the `ls' is no longer the first word in a simple
  51. command and therefore not eligible for alias expansion.
  52.  
  53. Chet
  54.  
  55. --
  56. ``The use of history as therapy means the corruption of history as history.''
  57.     -- Arthur Schlesinger
  58.  
  59. Chet Ramey, Case Western Reserve University    Internet: chet@po.CWRU.Edu
  60.  
  61.