Shell 将 IFS=$'\n' 解释为 IFS='n'

Shell 将 IFS=$'\n' 解释为 IFS='n'

我在 Ubuntu 12.04 LTS 服务器上使用 Bash shell,似乎 IFS=$'\n' 被视为 IFS='n'。

正在使用的脚本:

concat=$(echo -n "concat:" && find /home/jhvisser/bin/Streamripper_rips -name '*.aac' -mtime -1 -exec echo -n "{}|" \;)
echo $concat
IFS=$'\n'
for i in =$(echo "$concat" | sed -e 's/^concat://' -e 's/|$//' -e 's/|/\n/g');
    do rm "$i"
done

输出$(echo "$concat" | sed -e 's/^concat://' -e 's/|$//' -e 's/|/\n/g')

rm: cannot remove `=/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/Safe A': No such file or directory
rm: cannot remove `d Sou': No such file or directory
rm: cannot remove `d - Capital Cities (1).aac\n/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/U Got It Bad - Usher.aac\n/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/Life Of The Party - PRTY H3RO.aac\n/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/i': No such file or directory
rm: cannot remove `complete/True Love - Pi': No such file or directory
rm: cannot remove `k.aac\n/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/i': No such file or directory
rm: cannot remove `complete/The Other Side - Jaso': No such file or directory
rm: cannot remove ` Derulo.aac\n/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/Karma - Kristi': No such file or directory
rm: cannot remove `a Maria.aac': No such file or directory

它在每个“n”处都中断了。检查以下内容以查看所有文件的正确名称:

/home/jhvisser/bin/Streamripper_rips/Safe And Sound - Capital Cities (1).aac
/home/jhvisser/bin/Streamripper_rips/U Got It Bad - Usher.aac
/home/jhvisser/bin/Streamripper_rips/Life Of The Party - PRTY H3RO.aac
/home/jhvisser/bin/Streamripper_rips/incomplete/True Love - Pink.aac
/home/jhvisser/bin/Streamripper_rips/incomplete/The Other Side - Jason Derulo.aac
/home/jhvisser/bin/Streamripper_rips/Karma - Kristina Maria.aac

我想知道为什么会发生这种情况?它不应该在每个换行符处中断吗?

有关正在做的事情的更多详细信息,请查看这次聊天

答案1

建议如下:

问题是狂欢脚本被调用:在许多 Linux 系统上,sh 是 dash 而不是 bash。ANSI-C 引用是 bash 的一个特性。

理想情况下,添加#!/bin/bash为脚本的第一行,赋予其执行权限并直接调用它。

答案2

为什么不只是find /home/jhvisser/bin/Streamripper_rips -name '*.aac' -mtime -1 -delete

答案3

我没有权限发表评论,所以我不得不发布这个作为答案:

尝试转义 \,并将其替换s/|/\n/gs/|/\\n/g

相关内容