我学习Linux的命令,我练习,尝试写一个基本的shell脚本,列出子文件夹中的所有文件和文件,如ls *
,使用递归。递归在shell脚本
#!/bin/bash
# list-all: one command to list them all!!!!
listit() {
if [ -d "$1" ]
then
listit "$1"
else
echo "$1"
fi
}
ls | while read items; do
listit "$items"
done
然而,结果表明:
./list-all: line 16: 1101 Done ls
1102 Segmentation fault: 11 | while read items; do
listit "$items";
done
是因为外壳不允许递归?请帮忙,谢谢!
+1到你的学习工作。你是否知道'ls -R'或'find。键入-f'? –
@glennjackman,谢谢!我只是意识到你可以使用这些命令。虽然对于第二个,我认为它应该是“找到”。型F' – Yoland
事实上,由于为察觉错字 –