Marius van Witzenburg We fight for our survival, we fight!

10Jun/110

How to handle filenames containing whitespace in Bash

First capture the current IFS in $SAVEIFS and then replace it with a newline instead of spaces, now do your thing and afterwards restore the IFS with $SAVEIFS.

And yes, you can not use new lines in filenames ;-)

#!/usr/local/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in *
do
    echo "$f"
done
IFS=$SAVEIFS

Posted by mariusvw

Reacties (0) Trackbacks (0)

Nog geen reacties


Leave a comment

(required)

Nog geen trackbacks.