linux 脚本 怎么把一个目录下的所有文件名放到一个数组中,求大神指教
尝试的脚本:cd$pathnamels$pathname>folderlistchmod774folderlistcatfolderlistt=0whilereadLIN...
尝试的脚本:
cd $pathname
ls $pathname > folderlist
chmod 774 folderlist
cat folderlist
t=0
while read LINE
do
folder_list[$t]=$LINE
t=`expr $t + 1`
done < $folderlist
错误提示:
line 14: folderlist: Permission denied
chmod: cannot access `folderlist': No such file or directory
cat: folderlist: No such file or directory
draft.sh: line 23: $folderlist: ambiguous redirect 展开
cd $pathname
ls $pathname > folderlist
chmod 774 folderlist
cat folderlist
t=0
while read LINE
do
folder_list[$t]=$LINE
t=`expr $t + 1`
done < $folderlist
错误提示:
line 14: folderlist: Permission denied
chmod: cannot access `folderlist': No such file or directory
cat: folderlist: No such file or directory
draft.sh: line 23: $folderlist: ambiguous redirect 展开
3个回答
展开全部
IFS=$(echo -en "\n\b") #为了处理文件名中的空格、TAB
cd $pathname
j=0
for i in `ls -1`
do
folder_list[j]=$i
j=`expr $j + 1`
done
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
cd $pathname
name=*
arr=${name[@]}
echo @arr
name=*
arr=${name[@]}
echo @arr
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
declare -a FILE
FILE+=(*)
FILE+=(*)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询