【发布时间】:2017-03-06 04:21:52
【问题描述】:
在我的 bash 脚本中,我对目录中的文件进行了循环,并有一个简单的 if 语句来过滤特定文件。但是,它的行为不像我预期的那样,但我不明白为什么。
(我知道我可以在 for 循环表达式 (... in "*.txt") 中过滤文件扩展名,但在我的实际情况下条件更复杂。)
这是我的代码:
#!/bin/bash
for f in "*"
do
echo $f
if [[ $f == *"txt" ]]
then
echo "yes"
else
echo "no"
fi
done
我得到的输出:
1001.txt 1002.txt 1003.txt files.csv
no
我的期望:
1001.txt
yes
1002.txt
yes
1003.txt
yes
files.csv
no
【问题讨论】:
标签: string bash loops if-statement