user1385230
user1385230

Reputation:

Checking bash script argument doesn't work

I'm writing a bash script which runs other commands such as calling for yum to install a list of packages, and I'd like my script to silence the other commands by default, but let them output if I pass the -v argument. Issue I'm running into is that checking the value of $1 doesn't appear to be working correctly. Given the following code, my script will always echo "Yes":

if [[ "$1"=="-v" ]]; then
    echo "Yes"
else
    echo "No"
fi

If I just echo $1 and pass the script the -v, it echos -v as it should. What am I missing here?

EDIT: Found it. Kept playing with the script and changed the first line to this:

if [[ $1 == "-v" ]]; then

Works now?

Upvotes: 1

Views: 208

Answers (1)

AlG
AlG

Reputation: 15157

You need to add some spaces around your check: if [[ "$1" == "-v" ]]; then

Upvotes: 1

Related Questions