美文网首页
shell中把ls的数据保存在一个数组中

shell中把ls的数据保存在一个数组中

作者: 小王同学123321 | 来源:发表于2019-11-19 20:37 被阅读0次

需要将当前目录下的文件保存在一个所租中,数组时有所有索引的.顺次输出数组的长度和数组数组中的每一项

#!/usr/bin/env bash
#-*- coding:utf-8 -*-

count=0
declare -a array
for i in `ls`;do
    echo ${count}
    array[${count}]=${i}
    count=$(expr ${count} + 1)
done
echo ${#array[*]}
for j in ${array[*]}
do
    echo ${j}
done

相关文章

网友评论

      本文标题:shell中把ls的数据保存在一个数组中

      本文链接:https://www.haomeiwen.com/subject/rrigictx.html