当脚本和文件不在同一目录中时如何在 Unix 中使用 ls 函数

How to use ls function in Unix while the script and the files are not in the same directory

我有一个包含多个子文件夹的文件夹,例如包含脚本的 PROGRAMME 和包含纯文本文件的 URLS,以及用于输出的子文件夹 TABLEAUX。

现在我需要 ls 子文件夹 URL 并写入子文件夹 TABLEAUX。但是,当我在 for 循环中使用函数 ls 时,它说:

ls: cannot access 'URLS': No such file or directory

我猜是因为脚本和子文件夹不在同一个地方,我已经将目录更改为脚本所在的目录(如果不是,我无法执行脚本。)就像它显示的那样图片 2.

我的代码在这里:

#command: bash <name of script.sh> <folder_input> <folder_output>

dossier_url=
dossier_tableaux=
echo $dossier_url
echo $dossier_tableaux       # it's ok until here
for fichier in $(ls $dossier_url); do
echo $fichier;
done                # Ubuntu shows "ls: cannot access 'URLS': No such file or directory"

苏维埃!

我不应该将目录更改为 PROGRAMS,而应该使用命令:

bash PROGRAMMES/<name of scipt.sh> <input> <output>