如何使用循环语句将文件名作为输入传递给 shell 脚本?
How to use the file names passed as input to shell script using loop statements?
I am passing random number of files to a shell script and trying to
print it using a for loop. I tried something as below.
cat >> script.csh
for (( i=1; i<=$#; i++ ));
do
echo $i
done
so if I do ./script.csh xyz.txt abc.txt pqr.txt
I am expecting the output to be
xyz.txt
abc.txt
pqr.txt
But I am getting the output as
1
2
3
Any help is much appreciated. Thanks
您可以使用以下语法遍历程序参数:
for i in "$@"; do
echo $i
done
I am passing random number of files to a shell script and trying to print it using a for loop. I tried something as below.
cat >> script.csh
for (( i=1; i<=$#; i++ ));
do
echo $i
done
so if I do ./script.csh xyz.txt abc.txt pqr.txt
I am expecting the output to be
xyz.txt
abc.txt
pqr.txt
But I am getting the output as
1
2
3
Any help is much appreciated. Thanks
您可以使用以下语法遍历程序参数:
for i in "$@"; do
echo $i
done