Using BASH to manipulate all files in a directory - Cont
Chris pointed out I can simply do
Solution I:
Solution II:
Currently, I'm not sure what will break what will not if I set IFS=$'\n'. Certainly, if you are using some broken scripts that forgot to " ", with IFS=$'\n', you are still fine. Then, I'll rather locally use IFS=$'\n'. ;) If IFS=$'\n' does break other things, please tell me!
for i in *; do echo $i ; doneI can recall I struggled on the problem file names broken into parts. I spent much time to solve it. There is nothing much to argue if all other programs except your current script were written correctly. If you forgot to " " your $i, see what will happen below.
xman@sai tmp $ ls -QNow we have two solutions.
"text1.txt" "text version 2.txt"
xman@sai tmp $ for i in * ; do mv $i $i.txt ; done
mv: target `2.txt.txt' is not a directory
xman@sai tmp $
Solution I:
for i in *; do mv "$i" "$i.txt" ; doneBut do remember to double quote your file names. ;)
Solution II:
export IFS=$'\n'There is nothing wrong if you use "$i".
for i in * ; do $i $i.txt ; done
Currently, I'm not sure what will break what will not if I set IFS=$'\n'. Certainly, if you are using some broken scripts that forgot to " ", with IFS=$'\n', you are still fine. Then, I'll rather locally use IFS=$'\n'. ;) If IFS=$'\n' does break other things, please tell me!
Labels: BASH
1 Comments:
At 4/15/2013 5:25 PM , Anonymous said...
You can definitely see your expertise in the work you write.
The world hopes for more passionate writers such as you who
are not afraid to mention how they believe. All the time follow your
heart.
Look into my page ... Airplane Game
Post a Comment
Subscribe to Post Comments [Atom]
<< Home