how to

ttt is not set

Mar 1, 2024
softwares-and-toolsfishtest
1 Minutes
91 Words

TLDR

test -n returns true iff string is unset or (set and non-zero); (in fact because -n didn’t receive any string)

test -z return true iff string is unset or (set and zero);

Strange -n

1
# ttt is not set
2
if test -n $ttt
3
echo 1
4
else
5
echo 0
6
end

This outputs 1. (Strange)

1
set ttt ""
2
if test -n $ttt
3
echo 1
4
else
5
echo 0
6
end

This outputs 0.

Command -z

1
if test -z $ttt
2
echo 1
3
else
4
echo 0
5
end

This outputs 1.

1
set ttt ""
2
if test -z $ttt
3
echo 1
4
else
5
echo 0
6
end

This still outputs 1. Consistent.

Article title:ttt is not set
Article author:Julyfun
Release time:Mar 1, 2024
Copyright 2025
Sitemap