当前位置:网站首页>季更47/90
季更47/90
2022-04-21 15:36:00 【编程随想曲】
编程随想
Python中止程序
from sys import exit
exit(0) //程序正常退出
exit(1) //发生了错误
Bash数组操作
1. 数组赋值
arr[0] = 'a' //单个赋值
newArr=('a' 'b' 'c') //多个赋值
arr=([5]=a [9]=b [23]=c) //带序号赋值
mp3s=( *.mp3 ) //将当前目录的所有 MP3 文件,放进一个数组。
2. 数组读取
${newArr[0]} //读取位置1的元素
${foo[@]} //读取整个数组元素
3. 数组遍历
for i in "${newArr[@]}";
do
echo $i
done
4. 复制数组
copyArr = (${foo[@]})
5. 删除数组元素
unset newArr[2] //删除位置3的元素
6. 清空数组
unset newArr
7. 截取数组
${array[@]:position:length}
${newArr[@]:1:2} //返回 b c
${newArr[@]:0} //返回a b c
8. 关联数组
declare -A可以声明关联数组。
declare -A colors
colors["red"]="#ff0000"
colors["green"]="#00ff00"
colors["blue"]="#0000ff"
echo ${colors["blue"]} //#0000ff
9. 数组长度
${#newArr[*]}或${#newArr[@]}
10. 提取数组序号
${!array[@]}或${!array[*]}
11. 追加数组成员
newArr+=('d','e','f')
echo "${newArr[@]}" //a,b,c d,e,f
版权声明
本文为[编程随想曲]所创,转载请带上原文链接,感谢
https://cloud.tencent.com/developer/article/1985469
边栏推荐
- Oracle official announcement: Tencent JDK 18 ranks first in China!
- Leetcode 654: maximum binary tree
- 目标运动模型——匀速运动CV
- AcWing 1854. 晋升计数(模拟)
- MySQL8.0正确修改密码的姿势
- LeetCode 1572、矩阵对角线元素的和
- Smart public security QR code positioning alarm system development of mobile police app
- 盲盒项目的暴利玩法
- 智慧园区数融通-数字化赋能运营管理平台解决方案
- 返璞归真,多方安全计算要回归到“安全”的本源考虑
猜你喜欢

MATLAB入门到精通(一)

LeetCode 566、重塑矩阵

Emlparse: an ultra lightweight tool for batch parsing EML format e-mail

51页数字转型与“十四五”信息化规划

AcWing 1775. 丢失的牛 (模拟)

JDBC and database connection pool

C语言进阶第44式:函数参数的秘密(上)

107页企业数字化转型规划设计

Machine learning methods create learnable chemical grammars and construct synthetic monomers and polymers

Red team technology - parent process camouflage (mitre att & CK framework: t1134)
随机推荐
LeetCode 141、环形链表
Deltix Round, Summer 2021 E. Equilibrium
C语言进阶第44式:函数参数的秘密(上)
Red team technology - parent process camouflage (mitre att & CK framework: t1134)
How to synchronize client email to webmail and how to register email address?
目标运动模型——匀速运动CV
Ultimate doll 2.0 | observable practice sharing of cloud native PAAS platform
Deltix Round, Summer 2021 E. Equilibrium
什么是电子邮件的格式?企业邮箱地址是什么?
Huawei power PON distribution network solution
【unity笔记】L2Unity Shader基础
Machine learning methods create learnable chemical grammars and construct synthetic monomers and polymers
MATLAB入门到精通(一)
IT服务管理框架要怎么落地?看这篇就够了
智慧园区数融通-数字化赋能运营管理平台解决方案
107页企业数字化转型规划设计
mysql 将某个字段修改成自增
50页京东云·睿擎-打造企业数字化转型的敏捷引擎业务中台解决方案
Application of food safety law and relevant laws in patent examination
Solve i.mx6u driver transplantation LED flashing