I had to write to a shell script that parses a bunch of files. The
problem was some of the file names contained spaces. Here is a sample
scenario and the resolution.
Let's say you had files: "test 1" and "test 2" and you tried to do
something as trivial as:
#!/bin/bash
for f in `ls test*`
do
cat $f
done
the result would be:
cat: test: No such file or directory
cat: 1: No such file or directory
cat: test: No such file or directory
cat: 2: No such file or directory
The resolution would be:
#!/bin/bash
IFS="
"
for f in `ls test*`
do
cat $f
done
The explanations is that the IFS (interfield seperator) in the shell
defaults to space tab or newline. The space is part of the filename in
our case which will result in two seperate files.
So what we do at the begining of the script is set the IFS variable to
newline only.
Zaid,
Any gotcha will get someone :)
--
abulyomon
www.KiLLTHeUPLiNK.com
_______________________________________________
General mailing list
[email protected]
http://mail.jolug.org/mailman/listinfo/general_jolug.org