Comparing a variable to a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing a variable to a string
# 1  
Old 04-17-2009
CPU & Memory Comparing a variable to a string

Hi,

I am trying to write a script to show the status of a Network card.

Variables:
Code:
chosennic is a read variable
statuss=`/sbin/ifconfig $chosennic | grep MTU | awk '{print $1}'`
ipadd=`/sbin/ifconfig $chosennic | grep Bcast | awk '{print $2}' | awk -F : '{print $2}'`
submask=`/sbin/ifconfig $chosennic | grep Bcast | awk '{print $4}' | awk -F : '{print $2}'`
mac=`/sbin/ifconfig $chosennic | grep HWaddr | awk '{print $5}'`

I can then echo the MAC address, IP Address and Subnet mask of the chosen network card from these variables.

The variable statuss will contain the word "UP" if the network card is working correctly.

Here is a pseudo code of what I want to happen:
Code:
if $statuss = "UP" then 
echo $chosennic "is working correctly"
else
echo $chosennic "has encountered an error"
fi

Any help would be appreciated guys Smilie
Thanks
# 2  
Old 04-17-2009
Code:
#!/bin/ksh

statuss='UP'

if [ $statuss = "UP" ]; then
   echo $chosennic "is working correctly"
else
   echo $chosennic "has encountered an error"
fi

# 3  
Old 04-17-2009
ahhh, the was encasing it in [...] that i forgot.

Many thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check if string variable is a subset of another string variable

Below is my ksh shell script where I need to check if variable fileprops is a subset of $1 argument. echo "FILE PROPERTY: $fileprops" echo "PARAMETER3: $1" if ; then echo "We are Good. $line FILE is found to be INTACT !! " else echo... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

Comparing the value of a string index to a variable.

Hi, coding a simple program to compare an entered number to a randomly generated one. The number of digits are restricted so I'm just trying to figure out how to refer to the index value in a string and then compare it to the variable I want. I don't know if bash automatically indexes strings, so... (7 Replies)
Discussion started by: outofcookies
7 Replies

3. UNIX for Advanced & Expert Users

Help comparing string, please

Good morning, I need compare this string. if || || ; then But this line not work, somebody can say me what is the error. Thank you for advanced. (5 Replies)
Discussion started by: systemoper
5 Replies

4. Shell Programming and Scripting

How to append a string by comparing another string?

Hi , I have one file like BUD,BDL BUDCAR BUD,BDL BUDLAMP ABC,CDF,KLT ABISKAR ABC,CDF,KLT CORNEL ABC,CDF,KLT KANNAD JKL,HNM,KTY,KJY JAGAN JKL,HNM,KTY,KJY HOUSE JKL,HNM,KTY,KJY KATAK JKL,HNM,KTY,KJY KOLKA The o/p should be like BUD,BDL BUDCAR,BUDLAMP ABC,CDF,KLT... (4 Replies)
Discussion started by: jagdishrout
4 Replies

5. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

6. Shell Programming and Scripting

Problem in comparing 2 files string by string

Hi Champs, I am a newbie to unix world, and I am trying to built a script which seems to be far tough to be done alone by me..... " I am having a raw csv file which contains around 50 fields..." From that file I have to grep 2 fields "A" and "B"....field "A" is to be aligned vertically... (11 Replies)
Discussion started by: jitendra.pat04
11 Replies

7. Programming

string comparing in C

Hello, I need help with a program I'm trying to write for my moms science class, what it has to do is accept a user inputed string and search for it in a text file (file contains all the elements) The file looks like: H Hydrogen 1 He Helium 2 Li Lithium 3 Be Beryllium 4 ... If the... (0 Replies)
Discussion started by: duvalC
0 Replies

8. Programming

string comparing in C

Hello, I need help with a program I'm trying to write for my moms science class, what it has to do is accept a user inputed string and search for it in a text file (file contains all the elements) The file looks like: H Hydrogen 1 He Helium 2 Li Lithium 3 Be Beryllium 4 ... If the... (1 Reply)
Discussion started by: duvalC
1 Replies

9. Shell Programming and Scripting

COMPARING STRING VALUES TO A VARIABLE and return code dignostics

Hey Folks and Gurus there I am trying to replicate this logic in bash : (1) if ; then function1 parameters & function2 parameters & fi Is there an easy method esp one with regex that can do this comparision. e.g. $var is compared to this list ( case regardless ) (... (1 Reply)
Discussion started by: sieger007
1 Replies

10. Shell Programming and Scripting

comparing values of same variable

Hello all while writing a small script , i got stuck with this simple thing.Hope you guyz can help. Iam trying to read password echo"enter password" read $pwd now i have to check this echo"enter password to proceed" read $pwd now i have to check both the values of the... (2 Replies)
Discussion started by: coolkid
2 Replies
Login or Register to Ask a Question