0

I am new in bash.. Here is my code for bash script which will take file name as command line argument Code of file hello is :-

#!/bin/bash    
if ["$1"!= "abcd.txt"]; then
   echo Good
else
   echo Not Good
fi

when i am running

$hello abcd.txt

It's showing

/usr/bin/hello: line 2: [abcd.txt: command not found
Not Good

Where is the problem? Please help me as soon as possible. Thanks in Advance.

1 Answer 1

4

["$1"!= "abcd.txt"] is not syntactically right.

You need spaces after [, before ] and also before !=:

[ "$1" != "abcd.txt" ]
Sign up to request clarification or add additional context in comments.

1 Comment

To clarify why this is needed you should know that [ is a command and needs ] to be the last argument, while each other part should be an its own argument. These days however [ is for the most part a build in.

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.