前提
# 声明 x,y,z,默认字符串连接 [cmd] x=1 [cmd] declare -p x declare -- x="1" [cmd] y=1 [cmd] z=$x+$y && echo $z 1+1 [cmd] declare -i z [cmd] declare -p z declare -i z="1+1" # 声明 i_z 整形,加法不再默认字符串连接 [cmd] declare -i i_z=$x+$y && echo $i_z 2 [cmd] declare -p i_z declare -i i_z="2" # 数组,不需要声明 [cmd] a_x1=1 [cmd] a_x2=2 [cmd] declare -p a_x declare -a a_x='([0]="1" [1]="2")' # 声明只读,可以只有声明,不赋值,不可修改,不可 -p [cmd] declare -r r_x [cmd] declare -p r_x -bash: declare: r_x: not found [cmd] declare -r x [cmd] declare -p x declare -r x="1" [cmd] declare -r i_z # i_z 整形只读,只读设置不可撤销 [cmd] declare -p i_z declare -ir i_z="2" [cmd] i_z=4 -bash: i_z: readonly variable [cmd] declare +r i_z -bash: declare: i_z: readonly variable
标签:grep,只读,cmd,备忘,sed,声明,declare,bash From: https://www.cnblogs.com/wudeyun/p/16746556.html