[juneau-lug] Re: aliases

  • From: Jamie <jamie@xxxxxxxxxxxxxxxxx>
  • To: juneau-lug@xxxxxxxxxxxxx
  • Date: Wed, 24 Nov 2010 10:08:14 -0900

On 11/24/2010 09:21 AM, James Zuelow wrote:
> ----Original Message----
> From: juneau-lug-bounce@xxxxxxxxxxxxx
> [mailto:juneau-lug-bounce@xxxxxxxxxxxxx] On Behalf Of Jamie Sent:
> Wednesday, November 24, 2010 8:41 AM To: juneau-lug@xxxxxxxxxxxxx
> Subject: [juneau-lug] Re: aliases
>
>    
>> Thanks Mark - that works perfectly.
>>
>> Now I have 2 other aliases that don't work perfectly.  I wanted
>> shortcuts for the newest files in a directory or the biggest ones.
>>
>> These work in the current directory only
>> #newest files
>> alias nf='ls -lt $1 | head'
>> #biggest files
>> alias bf='ls -lS $1 | head'
>>
>> but when used on a different directory:
>>      
>>> nf /tmp
>>> head: error reading `/tmp': Is a directory
>>>        
>> Anyone - what am I doing wrong?  Omit the "| head" and they work.
>>
>>
>>      
> Bash doesn't like "complex" aliases -- when you add the pipe, it will break 
> because it is an alias.  When you enter the commands interactively, they work 
> but when you put them into .bashrc they won't.
>
> However you can define the complex alias as a function instead.
>
> Here is my .bashrc, with your nf and bf functions added to the end of my 
> aliases:
>
> ==========================================
> # some more ls aliases
> alias ll='ls -l'
> alias la='ls -A'
> alias l='ls -CF'
>
> function nf {
>          ls -lt $1 | more
> }
>
> function bf {
>          ls -lS $1 | more
> }
> ===========================================
>
> Change your aliases to functions in your .bashrc, source the file ( . .bashrc 
> ) and nf /tmp should work.
>
>
>    

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?


------------------------------------
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: