-1

here is my script:

#!/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

when I input nothing and press enter, the result is

para:
-z is ture
-n is ture

on the other hand, when I input something and press enter, the result is

para:qwer1234
-z is false
-n is ture

which confused me is the first result -n is ture. I think the -n and -z are antonyms, but why is the result the same? There must be something I ignore or misunderstand. I will be appreciate if someone can point out

Holger Just
  • 52,918
  • 14
  • 115
  • 123

1 Answers1

0

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

[ -n "$teatp" ]