String compare with list in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String compare with list in shell script
# 1  
Old 06-11-2009
Network String compare with list in shell script

Hi ,

I am new to shell scripting.

below is my requirement :
1) while running my .sh i will pass a string
2) i have to extract a folder name under a /config folder
3) i need to compare a input string in the folder name list
4) if that is true i have to continue my job else i have to give the message to the user

here is my code :

Code:
if [ $# -ne 1 ]; then
echo "Invalid arguments!"
echo ""
echo "job Name: $(basename $0) "
echo " Please pass the environment variable "
return 1
else
env_name="$1"
fi
 
LIST="`ls -ltr conf/ | grep -v "total" | grep -v "pre_swh" | awk '{ print $NF "," }'`";
if ["$env_name" in "$LIST"]
then
echo "correct"
else
echo "incorrect"
fi
counter1=`expr $counter1 + 1`
#done

while running this am gettin the error
sample2.sh[25]: [test: not found. Smilie

Please anyone help me on this

Last edited by vidyadhar85; 06-11-2009 at 10:47 PM.. Reason: code tag added
# 2  
Old 06-11-2009
if loop syntax is wrong
Code:
if [ "$env_name" = "$LIST" ] ; then

# 3  
Old 06-11-2009
Thank you vidyadhar.

but still am getting the same error..

is any other way there for getting the folder name and compare that with the input string?

Regards,
Raji.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies

2. Post Here to Contact Site Administrators and Moderators

Want a tcl script to compare a string in a file ignoring white spaces

Hi , I want a tcl script to search a string ignoring whitespaces in a .log file . It should correctly match . The string are as follows "Output-Maps 1 1 0 0 0" 1 and Active Intermediate-Maps 0 0 0 ... (1 Reply)
Discussion started by: kulua
1 Replies

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

4. Shell Programming and Scripting

Compare two files using shell script

Hi i want to compare two files and i need the o/p of only difference here the files file1 achilles aedxbepo aedxbwdm01 aedxbwdm02 albedo amarice ambrister anakin anton argon artephius asgard avatar aymara (10 Replies)
Discussion started by: venikathir
10 Replies

5. Shell Programming and Scripting

[awk]compare a number in a string with a list

Hi, I have a program written in awk and I want to extend it to do another task. My program is a list of CVS log reports of a repository. For each file, I have some fields. One of the fields is the comment field. I want to know how I can check if a comment (which is a free text field)... (8 Replies)
Discussion started by: sandeepk1611
8 Replies

6. Shell Programming and Scripting

Shell Script to Compare Two Files

I have a directory with about 6 files that we receive regularly. these 6 files contain information for 3 different units, 2 for each unit. files related to a specific unit are named similarly with a change in number at the end of the file. the numbers should be sequential. for each grouping of... (3 Replies)
Discussion started by: scriptman237
3 Replies

7. Shell Programming and Scripting

how to compare two lines using shell script?

how to compare two lines using shell script? (1 Reply)
Discussion started by: suman_dba1
1 Replies

8. Shell Programming and Scripting

String compare in shell script

Iam trying to compare the string in if else... but some how its not working following is the code On executing the above one its giving a error message ': bad number' in the above parameter l & k are numbers and dbfiles and patchefiles are array If i do echo ift working fine ... (2 Replies)
Discussion started by: kiranlalka
2 Replies

9. UNIX and Linux Applications

How to compare two files using shell script

hi experts please help me to compare two files which are in different directory file1<file will be master file> (/home/rev/mas.txt} ex x1 x2 file2 <will be in different folder> (/home/rev/per/.....) ex x3 x4 the filesinside per folder i need to compare with master file... (1 Reply)
Discussion started by: revenna
1 Replies

10. Shell Programming and Scripting

shell script cant recognize if else compare

hi I face the problem the if else statement dint return correct result for me my script as below: #!/bin/ksh sqlplus -s /nolog <<EOF connect databaseuser/password column num new_value num format 9999 set head off select count(*) num from table1; exit num EOF if ; then echo "$?"... (6 Replies)
Discussion started by: jaseloh
6 Replies
Login or Register to Ask a Question