[ILUG] Strip first three characters from filename
Colm Buckley
colm at tuatha.org
Sun Aug 10 22:03:53 IST 2008
>
> = Brian Foster <blf at utvinternet.ie>
>
= Colm Buckley <colm at tuatha.org>
>>
>
Just a note on the above; the "ls" is completely superfluous. The shell is
>> already expanding "*.mp3" to the list of all mp3 files in the current
>> directory; ls would only be necessary if you wanted to extract file
>> information other than the name [...]
>>
>
not quite.
> whilst I also detest the practice of using ls *.bar
> I also also realize it's not the same as *.bar
Yeah; I'm aware of the minutiae. For this problem, though, using the shell
glob expansion without invoking ls is much more correct, both in the
expected and pathological cases.
2. order may differ?
They should both be sorting according to the current locale rules.
3(most significant?) if nothing matches, *.bar _is_ *.bar
> whilst ls *.bar results in an error from ls, and in
> the case shown, the for-loop does not execute.
This depends on how the shell nullglob options are set. You can either get
a null expansion (which I always prefer; I think it's far more correct), or
a maintenance of the literal glob pattern as you suggest. I hate that
nullglob is not set by default; I can't think of any realistic cases where
keeping the literal glob is the more expected / less surprising behaviour.
Colm
--
Colm Buckley / colm at tuatha.org / +353 87 2469146
More information about the ILUG
mailing list