Tech Zone > Programming

A "grep" problem

(1/1)

Keith:
Consider:

[email protected]:~$ q=$(ls | grep dEsktop)     (i.e. a non-existent file)
[email protected]:~$ echo $q

[email protected]:~$

I want to test the value of "q" for its null value here.  It's not " " or "", so what might it be? 
Can anyone help?

Keith:
Found it at: https://serverfault.com/questions/7503/how-to-determine-if-a-bash-variable-is-empty

For a variable q:
               if [ -z "$q" ]; then ...... 
will detect if the variable is unset or the empty string "".

Navigation

[0] Message Index

Go to full version