【发布时间】:2016-08-16 01:19:10
【问题描述】:
我想创建一个 bash 脚本,它将命令行中的一个目录作为参数并打印我的所有子目录。我的脚本打印了这个目录所有的文件,并且没有进入 if 循环。我做错了什么以及如何解决?
#!/bin/bash
echo to argv[1] = $1
if [ -e $1 ] #exist the file
then if [ -d $1 ] # is directory
then if [ -r $1 ] #we can read
then for k in $(ls $1) #all the files in the arv[1]
do
echo $k #print all the files of directory
if [ -d $k ]
then echo $k
fi
done
fi
fi
fi
【问题讨论】:
标签: bash shell loops scripting directory