path=./*
new=""
for file in ${path}
do
if test -f $file
then
..........
fi
done
如何读取当前目录的文件名,并将这些文件名拼接成用,分隔的字符串
例如文件名:
1.txt
2.txt
3.txt
拼接后1.txt,2.txt,3.txt
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
用一条命令就可以了:
ls *.txt|sed -z 's/\n\b/,/g'
ls *.txt | paste -sd,