Bash技巧:对比 test判断字符串是否为空的用法

#!/bin/bash

function empty_string()
{
    if test -n $1; then
        echo '(1) -n $1  :' "No quote: not empty."
    fi

    if [ -z $1 ]; then
        echo '(2) -z $1  :' "No quote: empty."
    fi

    if test -n "$1"; then
        echo '(3) -n "$1":' "Quote   : not empty."
    fi

    if [ -z "$1" ]; then
        echo '(4) -z "$1":' "Quote   : empty."
    fi
}

empty_string "$1"

 

posted @ 2022-05-08 13:55  浅笑19  阅读(234)  评论(0编辑  收藏  举报