[juneau-lug] Re: aliases

  • From: James Zuelow <James_Zuelow@xxxxxxxxxxxxxxx>
  • To: "'juneau-lug@xxxxxxxxxxxxx'" <juneau-lug@xxxxxxxxxxxxx>
  • Date: Wed, 24 Nov 2010 10:32:12 -0900

----Original Message----
From: juneau-lug-bounce@xxxxxxxxxxxxx
[mailto:juneau-lug-bounce@xxxxxxxxxxxxx] On Behalf Of Jamie Sent:
Wednesday, November 24, 2010 10:08 AM To: juneau-lug@xxxxxxxxxxxxx
Subject: [juneau-lug] Re: aliases


>> 
> 
> Thanks for a working solution, James!
> 
> However I'm still puzzled as to why sometimes it works as a plain
> alias 
> and other times not.  In searching the web, there are aliases such as
> 
> alias ns='netstat -alnp --protocol=inet | grep -v CLOSE_WAIT | cut
> -c-6,21-94 | tail +2' 
> 
> which I assume works.  Any insight?
> 

I'm not really knowledgeable about bash internals, but I think it has something 
to do with how the pipes work as aliases.

When I try the above alias I get:

tail: cannot open `+2' for reading: No such file or directory

I edited it and cut off the last pipe with tail, and I find that the grep -v 
and cut commands are just ignored.

Note that this is a bashism.  Other shells seem to handle aliases better.  So 
even though that alias won't work in my bash shell, it might work for another 
shell.  Did the place you found the alias state which shell they were using?

I like bash, so I stick with it.  And setting up a function is just as easy as 
setting up an alias, so I don't worry about it too much.

I also take Mark's option quite often, putting small scripts into 
/usr/local/bin and running them.  

Using shell scripts in /usr/local/bin is a better option when you want to call 
them from cron or other scripts that won't have access to aliases in your 
.bashrc, or if you want everyone to be able to use the script without messing 
too much with user .bashrc files.  (I prefer to edit a script once, instead of 
editing n user's .bashrc.)

James Zuelow
Network Specialist
City and Borough of Juneau MIS
(907) 586-0236------------------------------------
The Juneau Linux Users Group -- http://www.juneau-lug.org
This is the Juneau-LUG mailing list.
To unsubscribe, send an e-mail to juneau-lug-request@xxxxxxxxxxxxx with the 
word unsubscribe in the subject header.

Other related posts: