首页 > 解决方案 > 引用/保护通过管道传输到 bash 的特殊字符?

问题描述

我有

$ cat afile 
file(1).txt ./adir

$ cat question.sh 
#!/bin/bash

sed -e 's/^/mv /' afile | bash

$ ./question.sh 
bash: line 1: syntax error near unexpected token `('
bash: line 1: `mv file(1).txt ./adir'

对于文件名中bash的特殊字符,我如何保护管道输入的行?可能还有其他我事先不知道的特殊字符,因此我正在寻找一种通用的方法来处理所有字符。()file(1).txt

标签: bashpipespecial-charactersquoting

解决方案



推荐阅读