- cat /var/lib/dpkg/info/skype.list
- for i in `cat /var/lib/dpkg/info/skype.list`; do echo rm $i; done
- IFS=$(echo -en "\n\b"); for i in `more /var/lib/dpkg/info/skype.list`; do echo rm \"$i\"; done
BASH Shell: For Loop File Names With Spaces
BASH Shell: For Loop File Names With Spaces
by Vivek Gite [Last updated: December 9, 2008]
BASH for loop works nicely under UNIX / Linux / Windows and OS X while working on set of files. However, if you try to process a for loop on file name with spaces in them you are going to have some problem. for loop uses $IFS variable to determine what the field separators are. By default $IFS is set to the space character. There are multiple solutions to this problem.
Set $IFS variable
Try it as follows:
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in *
do
echo "$f"
done
IFS=$SAVEIFS
OR
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
# set me
FILES=/data/*
for f in $FILES
do
echo "$f"
done
# restore $IFS
IFS=$SAVEIFS
No comments:
Post a Comment