Syntax to see if two variables match

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Syntax to see if two variables match
# 1  
Old 07-11-2011
Syntax to see if two variables match

I have a simple shell script to read create a mysql database as a particular user. Right now, I have the password set as a variable to make sure someone does not mistype the password. I want to take the hard coded password out of the file and make the user input the password twice to make they enter the password correctly. I know I can do the read -s twice and pass the password to two separate variables. I've been unable to find the syntax to see if the variables match and if not, make the user input the password again.

# 2  
Old 07-11-2011
easily you can compare the 2 variables using shell builtin tools
syntax #1

if [ "$var1" -eq "var2" ]

syntax #2

if [  "$var1"==  "$var2" ]

syntax #3

if [ "$var1" = "$var2" ]

syntax #4 Comparing two strings.

if [ $S1=$S2 ];
echo "S1('$S1') is not equal to S2('$S2')"
if [ $S1=$S1 ];
echo "S1('$S1') is equal to S1('$S1')"

# 3  
Old 07-28-2011
That's what I needed. Thank you for your assistance. Sorry, for the delay in responding, I was out of town.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies

2. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. UNIX for Beginners Questions & Answers

How to count lines of CSV file where 2 fields match variables?

I'm trying to use awk to count the occurrences of two matching fields of a CSV file. For instance, for data that looks like this... Joe,Blue,Yes,No,High Mike,Blue,Yes,Yes,Low Joe,Red,No,No,Low Joe,Red,Yes,Yes,Low I've been trying to use code like this... countvar=`awk ' $2~/$color/... (4 Replies)
Discussion started by: nmoore2843
4 Replies

4. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

5. Shell Programming and Scripting

Problems with variables syntax

Hi there I am really struggling :eek: to place a value in a variable with the following loop, having run out of ideas please can someone point me in the right direction? We first read two PIDs of a program (say calc) into an array, then we loop reading the details of those processes into a... (6 Replies)
Discussion started by: nathan.harris
6 Replies

6. Shell Programming and Scripting

print column value after exact match of variables in file

I have file like below summit hvar_rgrpd_10d_hvams17_ _kgr_prod.rec checksum checksum us europe summit hvar_rgrpd_10d_hvams17_ _kgr_prod.xml var summit us ... (5 Replies)
Discussion started by: manas_ranjan
5 Replies

7. Shell Programming and Scripting

match and assign variables

Hi guys, I'm currently writing a script for automating a FreeBSD ZFS setup (ZFSonRooT). I got stuck at one point for raidz(1,2 a.k.a raid5,6) and am in need of assistance. This is what I need. example: #!/bin/sh <- must stay sh echo -n "hdd list: " read hdd_list echo -n "hdd label list:... (2 Replies)
Discussion started by: da1
2 Replies

8. UNIX for Dummies Questions & Answers

Setting shell variables with ":" syntax

I nedd help on the below highlited one. can any one explain on this,How its work in shell scripting.. then that will be very great full... L_ABCD=${L_DBG:=N} Thanks Muddasas (3 Replies)
Discussion started by: muddasani
3 Replies

9. Solaris

<< match syntax error

Hi all, I have debugged this code and i am getting the syntax error at : `<<' unmatched.Please give solution trip while($i<= 10) do sqlplus -s $DBUSER/$DBPWD@$DBHOST << EOF > oraerror.log whenever sqlerror exit exit EOF i=`expr ${i} + 1` egrep 'ORA-121|ORA-01034'... (4 Replies)
Discussion started by: megh
4 Replies

10. Shell Programming and Scripting

syntax for variables in sed

I always kind of wondered this but I have a variable that I want to use in a search and replace. Basically I want to search a file for the string in my variable and replace it with something fixed but I'm unsure of the variable rule in sed. Here's generally what I have: sed 's/$name/newname/g'... (15 Replies)
Discussion started by: eltinator
15 Replies
Login or Register to Ask a Question