1834247 Members
2689 Online
110066 Solutions
New Discussion

Re: bash script

 
SOLVED
Go to solution
Oliver Schmitz
Regular Advisor

bash script

Hi all together,

only a short tiny thing: I am writing a short bash script but can not remember what the correct syntax is to compare the content of two shell variables in an if statement.

Thought it is:

if ["$T1"="$T2"]
then
anything
fi

What is wrong with that, cause it is not working.

Thanks a lot,

Oliver
Oliver Schmitz
1 REPLY 1
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: bash script

Missing whitespace and it's really a good/disciplined practice to enclose all variables in {}'s -- though that's not your problem here.

should be:
if [ "${T1}" = "${T2}" ]

note the spaces
after the "[" and before the "]" -- they are required.

If it ain't broke, I can fix that.