Handle special characters in bash for…in loop

前端 未结 3 960
轮回少年
轮回少年 2021-01-13 13:16

Suppose I\'ve got a list of files

file1
\"file 1\"
file2

a for...in loop breaks it up between whitespace, not newlines:

for         


        
3条回答
  •  情歌与酒
    2021-01-13 13:50

    UPDATE BY OP: this answer sucks and shouldn't be on top ... @Jordan's post below should be the accepted answer.

    one possible way:

    ls -1 | while read x; do
       echo $x
    done
    

提交回复
热议问题