How to compare a text value in a shell script and proceed accordingly
Hi,
I am triying to develop a shell script which has to read a variable from a text file is the variable is yes then it should proceed otherwise it should stop for eg my text file name is read.txt contents is build= yes/no # so if i i say want that if build is yes then it should proceed Please help!! |
You could use grep to extract the value, bash is not too good at this kind of thing but well,
Code:
VAR=$(grep 'build=' read.txt) Code:
VAR=$(grep 'build=' read.txt | head -n1) Code:
VAR=${VAR#build=} |
Quote:
Code:
shopt -s extglob # allow extended pattern matching operators Code:
c@CW8:~$ cat my.cfg |
Quote:
Code:
if grep -Pq "build\s*=\s*yes" read.txt |
Quote:
Code:
#!/bin/bash |
thank you for your response
but Sorry i forgot to tell i have to develop this script is csh #! /bin/csh -f setenv DISPLAY 192.23.9.69:1 set file="$(find /rubyscript/read.txt)" echo $file cat $file set var1=(grep 'build=no' read.txt) echo $var1 set var2="build=no" echo $var2 if ($var1 != $var2) then command not to build the script. else comand to build the script endif i was trying something like this but i think there is some problem with the syntex of variable declaration |
Quote:
Code:
set outcome = `grep -P "\bbuild\s*=\s*yes\b" /rubyscript/read.txt` |
#!/bin/csh -f
#set numlinks1 = `cat pri.txt | wc -l` set REPLY = `grep "yes" pri.txt` echo reply = $REPLY if($REPLY == "yes") then echo This is a yes else if($REPLY = "no") then echo This is a no endif endif Thanks every one i got it working. |
#! /bin/csh - f
set var1 = "buildyes" echo $var1 set var2 = `cat /rubyscript/read.txt ` echo $var2 switch ($var2) case buildno: echo no breaksw case buildyes: echo yes breaksw endsw even this worked fine for the csh |
All times are GMT -5. The time now is 05:49 PM. |