linux shell 读取for循环中出现难处理的数据之单引号错误实例

时间:2021-08-09 20:29:24

原语句:

#!/bin/bash

for test in I don't know if this'll work

do

echo "work:$test"

done

 

结果:

work:I

work:dont know if thisll

work:work

 

改成后语句:

#!/bin/bash

for test in I don\'t know if "this'll" work

do

echo "work:$test"

done

结果:

work:I

work:don't

work:know

work:if

work:this'll

work:work