假设A目录下面有1-10个子目录,分别名字为1-10,我要在这十个目录下分别建立一个文件,所以要做的其中一个步骤是读取当前目录的子目录列表,然后cd 1/ ; touch file ; cd .. ;
但是这个array数组我不知道怎么弄的,请高手帮忙。
进入子目录的数组
- numbchild
- 帖子: 107
- 注册时间: 2010-03-16 12:34
进入子目录的数组
My Blog: http://stardiviner.tumblr.com/
-
- 帖子: 101
- 注册时间: 2010-12-11 12:09
Re: 进入子目录的数组
我一点也不会,留名,帮顶
- astolia
- 论坛版主
- 帖子: 6386
- 注册时间: 2008-09-18 13:11
Re: 进入子目录的数组
使用for循环
代码: 全选
for d in *;do
touch "$d"/file
done
- numbchild
- 帖子: 107
- 注册时间: 2010-03-16 12:34
Re: 进入子目录的数组
可是要怎么读取子目录并排成一个数组呢?我试了ls和find -type d -print都不行,astolia 写了:使用for循环代码: 全选
for d in *;do touch "$d"/file done
就是要在${dir_arr[2]}这样应用单个的
My Blog: http://stardiviner.tumblr.com/
- astolia
- 论坛版主
- 帖子: 6386
- 注册时间: 2008-09-18 13:11
Re: 进入子目录的数组
代码: 全选
a=(*)
echo ${a[0]}
echo ${a[1]}
- numbchild
- 帖子: 107
- 注册时间: 2010-03-16 12:34
Re: 进入子目录的数组
yeah,我会这个引用,但是怎么把子目录变成一个一个的数组元素不会,ls是变成了只有一个元素的,astolia 写了:代码: 全选
a=(*) echo ${a[0]} echo ${a[1]}
find好像也不行:
array[*]=`find /path -type d -print `
但是这个只有一个元素
My Blog: http://stardiviner.tumblr.com/