I am trying develop a bash script which processes a list of files which may contain space names.
(I have already consulted Trouble in script with spaces in filename and Why I can't escape spaces on a bash script?, but can not seem to perfect my script.)
Here is my script. The actual process is more complicated which I reduce here to simple file
command.
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage is $0 <files to be tested>"
exit
fi
allfilestobetesed=$@
for filetobetested in "$allfilestobetested"
do
file "$filetobetested"
done
How do I improve my script?
*
or*.tex
or something similar. – Masroor Oct 23 '15 at 15:06"@"
not'"$@"'
Also it is generally more helpful to put theset -x
inside the script. – rocky Oct 23 '15 at 15:33set -x
ends up displaying the"$@"
part, I tried it locally and saw the same thing, it just turned out to be a typo further down – Eric Renouf Oct 23 '15 at 15:41