在下面的代码中我试图搜索文件。 在这里,我想排除以“#”开头的文件
请帮我解决这个问题。
#!/bin/bash
while read -r name
do
if [[ $name!= "#" ]]
then
find ./2016* -name *files.txt
fi
done < file.txt
出现以下错误:
conditional binary operator expected
syntax error near `"#"'
if [[ $name!= "#" ]]
最佳答案
在
$name
和!=
之间添加空格您需要排除以
#
开头的行。不仅仅是只有#
的行。为此,将模式更改为"#*"
在
find
命令中使用变量name
。
#!/bin/bash
while read -r name
do
if [[ $name != "#*" ]]
then
find ./2016* -name "$name"
fi
done < file.txt
这里提到了一种更好的排除注释行的方法 - bash loop skip commented lines
关于bash - 在 if 语句中传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38848148/