[juneau-lug] Re: aliases

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

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


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: