我该如何解决 while in bash 中的这个问题?

how can I solve this problem with while in bash?

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

for arch in $(ls  *.jpg);

正在</code>目录中。程序报错如下:</p> <pre><code>ls: Cannot access '*.jpg': File or directory does not exist

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

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

也没有必要使用ls

for arch in ""/*.jpg

我会使用以下方法:

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