# script op is different

**URL:** <https://community.unix.com/t/script-op-is-different/248170>\
**Category:** Shell Programming and Scripting\
**Created:** [August 29, 2009, 5:12am UTC](https://community.unix.com/t/script-op-is-different/248170 "2009-08-29T05:12:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lipun4u](https://community.unix.com/user_avatar/community.unix.com/lipun4u/32/4468_2.png) [@lipun4u](https://community.unix.com/u/lipun4u)\
**Post date:** [August 29, 2009, 5:12am UTC](https://community.unix.com/t/script-op-is-different/248170/1 "2009-08-29T05:12:58Z")

</div>

Consider the following script..

```plaintext
str1="Good"
str2="Bad"
str3=
[$str1 = $str2]
echo $?
[$str1 != $str2]
echo $?
[-n $str1]
echo $?
[-z "$str3"]
echo $?
[-z $str3]
echo $?
["$str3"]
echo $?

```

When I executed this, the o/p is

> [@](#):
>
> asit@asit-desktop:~/script$ sh str1.sh  
> 1  
> 0  
> 0  
> 0  
> 0  
> 1

But in my book, the op is totally different,

> [@](#):
>
> 1  
> 0  
> 0  
> 0  
> test: argument expected

What should I do ?? Which one I should accept ??

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [August 29, 2009, 5:56am UTC](https://community.unix.com/t/script-op-is-different/248170/2 "2009-08-29T05:56:00Z")

</div>

-deleted-

---

<div class="post-metadata">

**Author:** ![Vi-Curious](https://community.unix.com/letter_avatar/vi-curious/32/5_5575768a8748004e209b776fc1b2916d.png) [@Vi-Curious](https://community.unix.com/u/Vi-Curious)\
**Post date:** [August 29, 2009, 6:31am UTC](https://community.unix.com/t/script-op-is-different/248170/3 "2009-08-29T06:31:42Z")

</div>

If you understand what is being tested, you'd know which one to accept. Plus, you would accept the one you actually see executed, right?

```nohighlight
[$str1 = $str2]

```

tests to see if $str1 is equal to $str2. They are not so return false (1).

```nohighlight
[$str1 != $str2]

```

tests to see if $str1 is not equal to $str2. They are not so return true (0).

```nohighlight
[-n $str1]

```

tests to see if $str1 is not empty/null. It is not so return true (0).

```nohighlight
[-z "$str3"]
[-z $str3]

```

These are identical and test to see if $str3 is null. It is so return true (0).

```nohighlight
["$str3"]

```

tests to see if $str3 in not empty (-n is implied). It is so return false (1).
