[sclug] script or alias to page directory listings
Bob Franklin
r.c.franklin at reading.ac.uk
Mon Sep 5 12:19:38 UTC 2005
On Mon, 5 Sep 2005, 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)?
I suspect you want something like this:
#!/bin/bash
ls -al --color "${*:-.}" | more
The :- bit means that, if the previous parameter is not defined, use the
bit after it. So it assumes '.', if you miss out the argument. As for
handling wildcards, I'm not sure you can easily do that -- it is the
responsibility of the caller (usually the shell) to expand those; you
could pass the argument through something to expand them, but then you run
the risk of expanding things twice.
- Bob
--
Bob Franklin <r.c.franklin at reading.ac.uk> +44 (0)118 378 7147
Systems and Communications, IT Services, The University of Reading, UK
More information about the Sclug
mailing list