博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Bash 编程问题集
阅读量:2191 次
发布时间:2019-05-02

本文共 994 字,大约阅读时间需要 3 分钟。

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
}
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"

转载地址:http://lvdub.baihongyu.com/

你可能感兴趣的文章
【LEETCODE】66-Plus One
查看>>
【LEETCODE】26-Remove Duplicates from Sorted Array
查看>>
【LEETCODE】118-Pascal's Triangle
查看>>
【LEETCODE】119-Pascal's Triangle II
查看>>
【LEETCODE】88-Merge Sorted Array
查看>>
【LEETCODE】19-Remove Nth Node From End of List
查看>>
【LEETCODE】125-Valid Palindrome
查看>>
【LEETCODE】28-Implement strStr()
查看>>
【LEETCODE】6-ZigZag Conversion
查看>>
【LEETCODE】8-String to Integer (atoi)
查看>>
【LEETCODE】14-Longest Common Prefix
查看>>
【LEETCODE】38-Count and Say
查看>>
【LEETCODE】278-First Bad Version
查看>>
【LEETCODE】303-Range Sum Query - Immutable
查看>>
【LEETCODE】21-Merge Two Sorted Lists
查看>>
【LEETCODE】231-Power of Two
查看>>
【LEETCODE】172-Factorial Trailing Zeroes
查看>>
【LEETCODE】112-Path Sum
查看>>
【LEETCODE】9-Palindrome Number
查看>>
【极客学院】-python学习笔记-Python快速入门(面向对象-引入外部文件-Web2Py创建网站)
查看>>