[sclug] script or alias to page directory listings

J.Mann jon at spinis-associates.co.uk
Mon Sep 5 12:56:27 UTC 2005


> ls -al --color $* | more

Beware of "$*" - generally "$@" is a more appropriate choice.

  ls -al --color "$@" | more

>From the bash man page:

  Special Variables

  * Expands to the positional parameters, starting from one.  When the
    expansion occurs within double quotes, it expands to a single
    word  with the  value  of  each  parameter  separated by the first
    character of the IFS special variable.  That is, "$*" is equivalent to
    "$1c$2c...", where c is the first character of the value of the IFS
    variable.  If IFS is unset, the parameters are separated by spaces.
    If IFS is null, the parameters are joined without intervening
    separators.

  @ Expands to the positional parameters, starting from one.  When the
    expansion occurs within double quotes, each parameter expands to
    a separate word.  That is, "$@" is equivalent to "$1" "$2" ...
    When there are no positional parameters, "$@" and $@  expand  to
    nothing  (i.e., they are removed).

Best regards,
Jon Mann


On Mon, Sep 05, 2005 at 12:37:29PM +0100, John Stumbles wrote:
> In Ye Olde Days before GUIs[1] I used to have a script (called lsl) 
> which did
> ls -al --color $* | more
> 
> This was convenient, but breaks when filenames have spaces in them[2]. 
> Putting "" quotes around the $* works for single filenames but messes up 
> with wildcards or without an argument.
> 
> Can anyone suggest how to do this (either as a script or a bash command 
> alias)?
> 
> 
> 
> 
> [1] well, before I used a GUI on *n*x
> 
> [2] OK that's not directly the fault of GUIs, but it becomes much easier 
> to generate filenames containing spaces in a GUI.
> 
> -- 
> John Stumbles
> _______________________________________________
> sclug mailing list
> sclug at sclug.org.uk
> http://www.sclug.org.uk/mailman/listinfo/sclug
> 


More information about the Sclug mailing list