Welcome to %1$s. Please log in.

Login with username, password and session length
 
News: Keep The TechnoWorldInc.com Community Clean: Read Guidelines Here.
Techno World Inc - The Best Technical Encyclopedia Online! | Forum | THE TECHNO CLUB [ TECHNOWORLDINC.COM ] | Programming Zone | Shell Script | Bourne/bash shell scripts: string comparison

Mark David

Bourne/bash shell scripts: string comparison

To determine if the value of a variable ($var) is empty (null):

if [ $var == "" ]
then
  echo variable is null
fi


To determine if the value of a variable is not empty:

if [ $var != "" ]
then
  echo variable is not null
fi


To compare the contents of a variable to a fixed string:

if [ $var == "value" ]
then
   echo is the same
fi


To determine if variable's contents are not equal to a fixed string:

if [ $var != "value" ]
then
  echo not the same
fi

Recent Updates

[August 11, 2025, 08:33:44 AM]

[August 11, 2025, 08:33:44 AM]

[August 11, 2025, 08:33:44 AM]

[August 11, 2025, 08:33:44 AM]

[May 13, 2025, 08:34:25 AM]

[May 13, 2025, 08:34:25 AM]

[May 13, 2025, 08:34:25 AM]

[April 12, 2025, 08:24:20 AM]

[April 12, 2025, 08:24:20 AM]

[April 12, 2025, 08:24:20 AM]

[April 12, 2025, 08:24:20 AM]

[March 12, 2025, 09:35:30 AM]

[March 12, 2025, 09:35:30 AM]

Subscriptions

Get Latest Tech Updates For Free!

Resources

  

Bourne/bash shell scripts: string comparison

Started by Mark David, March 16, 2007, 08:02:09 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

  Print     Print       Print