與 linus 條件 '-z' '-n' 混淆 (Confuse with the linus conditions '-z' '-n')


問題描述

與 linus 條件 '‑z' '‑n' 混淆 (Confuse with the linus conditions '‑z' '‑n')

這是我的腳本:

#!/bin/bash

read ‑p "para:" teatp

if [ ‑z $teatp ]; then
    echo '‑z is ture'
else
    echo '‑z is false'
fi

if [ ‑n $teatp ]; then
    echo '‑n is ture'
else
    echo '‑n is false'
fi

當我什麼都不輸入並按回車時,結果是

para:
‑z is ture
‑n is ture

另一方面,當我輸入一些東西並按回車時,結果是

para:qwer1234
‑z is false
‑n is ture

讓我困惑的是第一個結果‑n is ture。我認為 ‑n‑z 是反義詞,但為什麼結果相同?一定有什麼我忽略或誤解的。如果有人能指出,我將不勝感激


參考解法

方法 1:

the #testp should be quote by double quotation marks? like:

[ ‑n "$teatp" ]

(by atticusatticus)

參考文件

  1. Confuse with the linus conditions '‑z' '‑n' (CC BY‑SA 2.5/3.0/4.0)

#conditional-statements #linux






相關問題

在 SSRS 中使用條件來提高可見性 (using conditionals in SSRS for visibility)

Smarty - {IF} {/IF} 內的條件太多 (Smarty - Too many conditions inside {IF} {/IF})

awk 如果有多個條件拋出錯誤 (awk if with multiple condition throws error)

正則表達式錯誤,嵌套標籤 (Regex error, nested tags)

警告:分配條件 (Warning: Assignment in condition)

JavaScript 中的條件語句 (Conditional Statement in JavaScript)

與 linus 條件 '-z' '-n' 混淆 (Confuse with the linus conditions '-z' '-n')

如果條件為真,則將表達式添加到循環中 (if condition is true, add an expression to a loop)

為什麼用多態性替換條件有用? (Why is replacing conditionals with polymorphism useful?)

如何使用條件將一個數據框列的值與另一個數據框列的值匹配? (How do you match the value of one dataframe's column with another dataframe's column using conditionals?)

使用另一個數據框的條件創建一個新列 (Create a new column with a condition of another dataframe)

排除具有空值的 Python 列表 (Excluding Python Lists With Empty Values)







留言討論