Home > Database > Mysql Tutorial > bash一些技巧

bash一些技巧

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:41:30
Original
1083 people have browsed it

1. 设置当命令带有非0返回时立刻退出:set -e 2. 十六进制转换为十进制:num_16=`echo ibase=10;obase=16;$num|bc` 3. IP合法性校验 function valid_ip() { local ip_local=$1 local stat=1 if [[ $ip_local =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{

1. 设置当命令带有非0返回值时立刻退出:set -e

2. 十六进制转换为十进制:num_16=`echo "ibase=10;obase=16;$num"|bc`

3. IP合法性校验

function valid_ip()

{

    local  ip_local=$1

    local  stat=1

    if [[ $ip_local =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then

        OIFS=$IFS

        IFS='.'

        ip_local=($ip_local)

        IFS=$OIFS

if [[ -z ${ip_local[0]} ]] || [[ -z ${ip_local[1]} ]] || [[ -z ${ip_local[2]} ]] || [[ -z ${ip_local[3]} ]]

then

return 1

fi

        [[ ${ip_local[0]} -le 255 && ${ip_local[1]} -le 255 \

            && ${ip_local[2]} -le 255 && ${ip_local[3]} -le 255 ]]

        stat=$?

    fi

    return $stat

}

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
debian - bash configuration for new linux users
From 1970-01-01 08:00:00
0
0
0
git bash crashes
From 1970-01-01 08:00:00
0
0
0
python3.x - How does git bash run .bat files?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template