0

I am a beginner is bash and i really need some help here.The conditional part of the script is not executing for some reason. Here is my code

#!/bin/bash
#Checking Os
os=$(lsb_release -si)
echo $os
if [ $os == "CentOs" ]; then
echo 'success'
fi

Now part till echo $os works fine and out is

CentOs

but 'success' don't get output :(

Any idea why if part don't get executed.What is wrong with the syntax.I get no errors whatsoever

2 Answers 2

1

Linux is case sensitive. Running "lsb_release -a" on my CentOS install results in "CentOS" - note that the trailing "S" is uppercase. Change your code to test for the properly capitalized string, and it should work.

Sign up to request clarification or add additional context in comments.

Comments

1

Hope this helps:

#!/bin/bash
#Checking Os
os=$(lsb_release -si)

# !quote variables when passing them to commands like echo!
echo "$os"

# A space between ] and ; Quote "$os". Note: = instead of == is OK as well.
# Note that it's not CentOs, it's CentOS
if [ "$os" == "CentOS" ] ; then
  echo 'success'
fi

The ultimate reference: Advanced Bash Scripting Guide

3 Comments

Hhmm. My bash manual says, that = and == inside a conditional expression are equivalent.
@A.H. Thx for the tip! I didn't know this. Also I would not say that I'm a bash guru. Just wanted to help the newbie opener a little bit. Have updated the post to prevent from giving useless information.....
Thanks but it still didn't work , sucess is still not echoed on my end , Only value of $os is display

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.