有趣的Shell字符串


 

#!/usr/bin/env bash
str=$1
if [[ "$str" = "" ]]; then
     echo "1 empty"
fi

if [[ "$str" = " " ]]; then
    echo "2 empty"
fi

if [[ "$str" = "0" ]]; then
    echo "3 empty"
fi

if [[ "$str" = "00" ]]; then
    echo "4 empty"
fi

if [[ "$str" -eq 0 ]]; then
    echo "5 empty"
fi

if [[ "$str" -eq 000 ]]; then
    echo "6 empty"
fi

if [[ "$str" -eq '0' ]]; then
    echo "7 empty"
fi

if [[ "$str" -eq '00' ]]; then
    echo "8 empty"
fi
## show results
1 empty
5 empty
6 empty
7 empty
8 empty
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s