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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Comparing a String variable with a string literal in a Debian shell script
# 1  
Old 03-14-2012
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: [{BOOK1}: command not found
2

Please can anyone offer any advise.

Many thanks for your help

This is the test CODE follows:
Code:
#!/bin/sh
BOOK_LIST="BOOK1 BOOK2"

for BOOK in ${BOOK_LIST}
do
 if [{$BOOK} = "BOOK1"]
 then echo '1'
 else
      echo '2'
  fi

done

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data
# 2  
Old 03-14-2012
Code:
 if [ "$BOOK" = "BOOK1" ]

Be careful, recpect the needed spaces for the square brackets...


I would put a
Code:
 read KYB

so you have to press a key to continue after the fi so that you see where you are... (end on loop first /secand pass) othewise it is going to display 1 and 2 without you knowing where from...

Last edited by vbe; 03-14-2012 at 09:43 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Fgrep literal string from a file

have a file1 aaa-bbb-ccc-abcd aaa-bbb-ccc-bacd aaa-bbb-ccc-aaad aaa-bbb-ccc-ahave another file2 aaa-bbb-ccc-a fileusing the fgrep command, trying to have only the literal string returned. fgrep -f file2 file1 is returning aaa-bbb-ccc-abcd aaa-bbb-ccc-aaad aaa-bbb-ccc-aOnly looking for... (1 Reply)
Discussion started by: jimmyf
1 Replies

2. Shell Programming and Scripting

Shell Script (ksh) - SQLPlus query filter using a string variable

Using ksh, I am using SQLPlus to execute a query with a filter using a string variable. REPO_DB=DEV1 FOLDER_NM='U_nmalencia' FOLDER_CHECK=$(sqlplus -s /nolog <<EOF CONNECT user/pswd_select@${REPO_DB} set echo off heading off feedback off select subj_name from subject where... (5 Replies)
Discussion started by: nkm0brm
5 Replies

3. 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

4. Shell Programming and Scripting

Pass a variable string in To_Date Oracle function in shell script

Hello, I am trying to execute an SQL query from shell script. A part of script is something like this: fromDate=`echo $(date +"%F%T") | sed "s/-//g" | sed "s/://g"` $ORACLE_HOME/sqlplus -s /nolog <<EOD1 connect $COSDBUID/$COSDBPWD@$COSDBSID spool... (4 Replies)
Discussion started by: sanketpatel.86
4 Replies

5. 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

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. 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

8. Shell Programming and Scripting

Shell Script to Search for a particular String and copy the timestamp to a variable

Hi, We Perfrom Loads to the database through a Perl script which generates a statistics file. I need to read the statistics. the Statistics file looks something like below: Process Beginning - 08-26-2010-23.41.47 DB2 CONNECTION SUCCESSFUL! Ready to process and load file: FILENAME # of... (2 Replies)
Discussion started by: Praveenkulkarni
2 Replies

9. Shell Programming and Scripting

Comparing a variable to a string

Hi, I am trying to write a script to show the status of a Network card. Variables: 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}'`... (2 Replies)
Discussion started by: mikejreading
2 Replies

10. 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
Login or Register to Ask a Question