Author Topic: A "grep" problem  (Read 771 times)

0 Members and 1 Guest are viewing this topic.

Offline Keith

  • Hero Member
  • *****
  • Posts: 851
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
A "grep" problem
« on: May 25, 2018, 03:40:17 pm »
Consider:

keith@T500:~$ q=$(ls | grep dEsktop)     (i.e. a non-existent file)
keith@T500:~$ echo $q

keith@T500:~$

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?


Offline Keith

  • Hero Member
  • *****
  • Posts: 851
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
Re: A "grep" problem
« Reply #1 on: May 25, 2018, 07:49:00 pm »
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 "".

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal