Linux的阅读空格和特殊字符 [英] Linux read whitespaces and special characters

查看:192
本文介绍了Linux的阅读空格和特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想是因为我需要删除文件,该字符串的名称以空格和特殊字符阅读。我不知道该如何处理\\,并在最后一个读取的空间;我可能做错了。

I want to read with whitespaces and special characters because I need to delete file with the name of that string. I don't know how to deal with "\" and last spaces in read; I am probably doing it wrong.

     while read LINE
  do
    for arg in $LINE
    do  
    if [ "${args}" = "" ]
    then
        args="${args}"
    else
        args="${args}' '"
    fi     
    args="${args}${arg}"
    done

我需要做这样的事情回声sadsad asddsa;' dsasa | ./sth.sh | xargs的-l RM -f

我想我需要设置IFS为|但它不正常工作。我需要读取输入端调用它。

I think that I need to set IFS to "|" but it doesn't work properly. I need to read input end call it.

编辑:好吧,我想我只需要做的事情的xargs和sed

Ok, I think I only need to do something with xargs and sed.

现在,已经差不多吴丹我有一些错误,但我得到的文件名

Ok, almost thant I have some errors but I get file name

find  *.txt -print0 | xargs -0 rm -f

这正常工作对我:)。问题可能解决的。

This works fine for me :). Problem probably solved.

推荐答案

尝试:

while read -r line
do
  echo rm -- "$line"
done

-r 表示反斜杠没有得到特殊待遇。

-r means that backslash don't get special treatment.

这篇关于Linux的阅读空格和特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆