在bash中如何解决这个问题?

在bash中如何解决这个问题?,bash,while-loop,glob,ls,Bash,While Loop,Glob,Ls,我有一个包含.jpg文件的图像目录,我正在执行以下代码: for arch in $(ls $1 *.jpg); 是目录中的$1。程序出现以下错误: ls: Cannot access '*.jpg': File or directory does not exist 我做错了什么?提前感谢。使用/将目录名连接到内容的通配符 也不需要使用ls for arch in "$1"/*.jpg 我将采用以下方法: for arch in "$1"/*.jpg; do [ -f "$arch

我有一个包含
.jpg
文件的图像目录,我正在执行以下代码:

for arch in $(ls $1 *.jpg);
是目录中的
$1
。程序出现以下错误:

ls: Cannot access '*.jpg': File or directory does not exist

我做错了什么?提前感谢。

使用
/
将目录名连接到内容的通配符

也不需要使用
ls

for arch in "$1"/*.jpg

我将采用以下方法:

for arch in "$1"/*.jpg; do
   [ -f "$arch" ] || continue
   file="${arch##*/}"
   # do your stuff here with "$file" which is the basename
done

您的意思是“$1”/*.jpg中的拱的
?请注意: