Bash 编程问题集
来源:互联网 发布:php中while 编辑:程序博客网 时间:2024/05/16 05:51
1, bash 中各个命令行 各部分含义
$0就是该bash文件名
$?是上一指令的返回值
$*所有位置参数的内容:就是调用调用本bash shell的参数。
$@基本上与上面相同。
"$*"返回的是一个字符串,字符串中存在多处空格。
"$@"返回多个字符串。
$#返回所有位置参数的个数。
cy_get_subnet_from_ip_mask_pair() {
local ip=$1
local mask=$2
if ! cy_check_ip $ip || ! cy_check_ip $mask; then
cy_err "need IP, Mask (format check failed: $ip,$mask)"
fi
IFS='.' read -a a_ip <<< "$ip"
IFS='.' read -a n_ip <<< "$mask"
res=""
for i in 0 1 2 3; do
res="${res}.$(( ${a_ip[$i]} & ${n_ip[$i]} ))"
done
res=${res:1}/$(cy_netmask_ip_to_number $mask)
echo $res
}
local ip=$1
local mask=$2
if ! cy_check_ip $ip || ! cy_check_ip $mask; then
cy_err "need IP, Mask (format check failed: $ip,$mask)"
fi
IFS='.' read -a a_ip <<< "$ip"
IFS='.' read -a n_ip <<< "$mask"
res=""
for i in 0 1 2 3; do
res="${res}.$(( ${a_ip[$i]} & ${n_ip[$i]} ))"
done
res=${res:1}/$(cy_netmask_ip_to_number $mask)
echo $res
}
2, systemdisksarray=systemdisks
systemdisksarraymaxlen=$maxsystemdiskscount
systemdisksarraylen=`echo "$systemdisks" | awk '{print NF}'`
# array service
array() {
local disks="$1" # element into array
local pretag="$2" # array name
local index=0
for var in $disks
do
eval "$pretag$index=$var"
index=`expr $index + 1`
done
}
getarrayelement() {
newname=${1}${2} # pretag and index , as same as the array()
eval "echo $`echo $newname`"
}
array "$systemdisks" "$systemdisksarray"
systemdisksarraymaxlen=$maxsystemdiskscount
systemdisksarraylen=`echo "$systemdisks" | awk '{print NF}'`
# array service
array() {
local disks="$1" # element into array
local pretag="$2" # array name
local index=0
for var in $disks
do
eval "$pretag$index=$var"
index=`expr $index + 1`
done
}
getarrayelement() {
newname=${1}${2} # pretag and index , as same as the array()
eval "echo $`echo $newname`"
}
array "$systemdisks" "$systemdisksarray"
0 0
- Bash 编程问题集
- bash编程
- bash编程
- bash编程
- Bash 编程
- Bash 编程
- Bash 编程
- Bash基本编程(一)
- Bash基本编程(二)
- Bash基本编程(三)
- BASH脚本编程
- BASH脚本编程
- Bash编程笔记
- Bash编程笔记
- Bash脚本编程基础
- bash 脚本编程
- Bash编程 - 读写文件
- Bash编程 - 命令行参数
- Linux shell脚本中与if相关参数说明
- 一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10
- The prefix "context" for element "context:component-scan" is not bound.
- js 遇到的问题-使用for循环给同一个文本框赋值
- 面试准备-外包公司、小企业-2015/1/16
- Bash 编程问题集
- SQL 语句转换格式函数Cast、Convert
- Android 源码开发----Ubuntu14.04下Android-4.2编译过程
- Android Spinner!---?android:attr/spinnerDropDownItemStyle
- 黑马程序员——内存管理
- 在Android开发中使用icon font的代码和方法
- POJ 2262 Goldbach's Conjecture
- Linux统一设备模型之精讲
- 动态规划之背包问题