收藏文章 楼主

linux shell 数组的操作,数组角标与对应的元素;一个获取查看目录文件脚本

版块:shell   类型:精华   作者:小绿叶技术博客   查看:2584   回复:2   获赞:13   时间:2020-06-11 10:30:50

#!/bin/bash


# catalog=(                                     # 素组的格式是小括号:请将IP地址放置括号内,分隔符是换行或者空格

# 111                                    

# 222

# )


# echo ${catalog[$1]} # 指定数组角标对应的元素;[$1] 角标数字(游标卡尺): 指定第一个元素

# ${catalog} 数组:数据仓库


# echo ${#catalog[*]} # 素组元素总个数





read -p "请输入目录:" catalog

 [ˈkætəlɔg]目录


# catalog=/www/wwwroot/guzheng



filecatalog=(

$(ls $catalog)

)


quantity=${#filecatalog[*]} #  [ˈkwɑn(t)ədi] 数量;kuan t ti

echo "当前目录(数组)中文件个数数量为:$quantity"


frequency=$quantity # [ˈfrikwənsi] 次数; fei ou kuan si

for((i=1;i<=$frequency; i++))

do

echo "正在依次打印该目录的的文件信息:  ${filecatalog[$i]}  文件对应的角标为:$i"

done


read -p "请选择角标进行删除复制修改移动操作:" cfile

######################    重点  ##################

###在数组变量中指定角标###  达到数组相互可逆

operation=${filecatalog[$cfile]} #  operation [ˌɑpəˈreɪʃ(ə)n] 操作


echo "您选择的角标对应的文件或目录名称为:"  $operation






sed -i "/^$/d" 1.sh ; chmod 755 1.sh ; ./1.sh 

提供企业建站服务,免费网防系统,提交信息登录 http://yundun.ddoss.cn 邮箱: proposal@ddoss.cn 
回复列表
默认   热门   正序   倒序

回复:linux shell 数组的操作,数组角标与对应的元素;一个获取查看目录文件脚本

头像

用户名:

粉丝数:

签名:

资料 关注 好友 消息