Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
968 views
in Technique[技术] by (71.8m points)

bash - for name in `ls` and filenames with spaces

next code doesnt work because of spaces in file names, How to fix?

IFS = '
'
for name in `ls `
do
    number=`echo "$name" | grep -o "[0-9]{1,2}"`
    if [[ ! -z "$number" ]]; then
        mv "$name" "./$number"
    fi
done
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just don't use command substitution: use for name in *.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...