Sun 23 Apr 2006
Nombres con espacios en shells
Enviado al blog por el pinche cash segun el bajo la categoria Linux, Scripting
Obtenido de http://www.killtheuplink.com
Hacia rato que ya habia tenido ese problema, nunca me clave mucho para resolverlo…
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*`
docat $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 directoryThe resolution would be:
#!/bin/bash
IFS=�?
�?for f in `ls test*`
docat $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.
Incoherencias parecidas y calificaciones a este post:


