Home arrow Bash Programming
Bash Programming
How to Evaluate an Expression in Bash PDF  
Digg Reddit Stumble Upon Facebook Twitter Google Technorati Bookmark
Friday, 15 October 2010
Of course with if statement:

Create a file filename.txt with yes text in it.

echo "ok" > filename.txt

Then use the following Bash code:

example1.sh
  1. #!/usr/local/bin/bash
  2.  
  3. var=`cat filename.txt`
  4.  
  5. if [ "$var" = "yes" ]; then
  6.      echo "yessss!"
  7. fi

 Line 3 runs command cat filename.txt and then put the output of that command to variable $var.

Line 5 compare content of $var variable with "yes" string and if strings are equal it will display echo on the screen.

Last Updated ( Friday, 15 October 2010 )
 

Misc

Linux Tips

Polls

What is your favorite Linux Distribution ? (we just added Mint and reset the pool data)