gpt4 book ai didi

linux遍历目录中的文件

转载 作者:太空狗 更新时间:2023-10-29 11:24:58 24 4
gpt4 key购买 nike

我正在尝试遍历目录中的每个文件。到目前为止,这是我的代码。

while read inputline
do
input="$inputline"
echo "you entered $input";

if [ -d "${input}" ]
then
echo "Good Job, it's a directory!"

for d in $input
do
echo "This is $d in directory."
done
exit

我的输出总是只有一行

this is $input directory.

为什么这段代码不起作用?我做错了什么?

很酷。当我回显时,它会打印出来

$input/file

为什么要这样做?它不应该只打印出没有目录前缀的文件吗?

最佳答案

for d in "$input"/*

关于linux遍历目录中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1732861/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com