
Colin Palmer wrote:
On Fri, 2005-08-12 at 11:35 +1200, Jonathan Purvis wrote:
Make yourself and empty directory and try these 3 commands:
touch file\ 1 file\ 2 file\ 3 for name in * ; do echo $name ; done for name in `ls -1 | sort -r` ; do echo $name ; done
I'd like some way of making the output of the 3rd command be the output of the 2nd, only reversed. Instead it prints a line break instead of a space as bash as split the arguments given to for on spaces.
You can get what you want by changing $IFS (bash's input field separator):
IFS=; for name in `/bin/ls -1 | sort -r` ; do echo $name ; done
That seemed to produce the correct output, but echo was only called once. But with your idea about using IFS, i managed to get this, which does work: IFS=" "; for name in `/bin/ls -1 | sort -r` ; do echo line: $name ; done Thanks for your help.