>>>>> "Padraig" == Brady, Padraig <Padraig.Brady at compaq.com> writes:
Padraig> I'm confused by your question.
Sorry. That's probably due to the fact that I was confused while
asking the question.
Padraig> As I understand it ls checks to see if stdout is a tty
Padraig> and if not it outputs 1 file per line. You can force
Padraig> this output format by doing ls -1 Aliases can confuse
Padraig> things so do /bin/ls -1 to test the various options.
Yes. Harry and others have already explained that and it rang a bell.
Can you rely on all shell commands working this way or do you have to
take it on a one by one basis?
ls -1 is redundant for pipelines though, isn't it? Maybe you would
want to use ls -1 if you were redirecting output to a file for later
processing.
Padraig> As for your problem, it might be better to use find
Padraig> instead of ls to generate the file list? What happens if
Padraig> you have a filename that contains a : or \n in the
Padraig> example you present?
Yes. That is a weakness for sure.
Padraig> How about the following (I haven't tested it) ?
Padraig> #!/bin/sh #pass either filenames or nothing #note doesn't
Padraig> touch directories
Padraig> if [ $# = 0 ] then FILES=$(find -type f -maxdepth 1) else
Padraig> FILES="$@" fi
Padraig> for FILE in $FILES do DEST=$(echo $FILE | tr A-Z a-z) if
Padraig> [ "$DEST" != "$FILE" ] then mv -i "$FILE" "$DEST" #-i
Padraig> prompts for confirmation (-f is opposite) fi done
Padraig> Note the above doesn't handle \n in a filename either,
Padraig> but you can with a few more tr commands in various
Padraig> places.
That is excellent. Thank you very much. It removes all the non-ops for
files which are already all lowercase although mv probably doesn't do
too much processing in that case anyway.
This was also suggested:
find root_of_cd -depth -exec mv {} `echo {} | tr A-Z a-z` \;
which depends on the version of find being able to reference {} twice
but most modern finds allow that.
Thanks for your help. I am much less confused now.
Dermot.
--
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!