【发布时间】:2015-08-30 12:00:50
【问题描述】:
首先,大家好,这是我在这里的第一篇文章。
我发誓我已经检查了该网站是否有类似问题,以避免“关于同一论点的双重帖子”问题,但他们都没有完全回答我的问题。
问题是,在下面的代码中,当我调用将扩展名作为第一个参数传递给它的脚本时,我总是收到"There are no files with this extension" 消息。
#!/bin/bash
if [ "$1" ];
then
file=*."$1";
if [ -f "$file" ];
then
for i in "$file";
[...do something with the each file using "$i" like echo "$i"]
else
echo "There are no files with this extension";
fi;
else
echo "You have to pass an extension"
fi;
我尝试使用双括号,在嵌套的 if 中使用和不使用引号,在 if 中直接使用*."$1",但这个解决方案都不起作用。
【问题讨论】:
标签: bash argument-passing