1

I just started shell scripting, and I need to check if a file exists so I used command :

    if [[-e "./doc/issues/$1.md" ]]; 

But the command seems to be invalid.

Does anybody knows why ?

1 Answer 1

5

You forgot to put a whitespace before -e, try :

if [[ -e "./doc/issues/$1.md" ]]; 
Sign up to request clarification or add additional context in comments.

3 Comments

The reason the space is required is that [[ is not mere syntax: it is (essentially) a command, and like every command, it needs a space to separate it from its arguments.
Spaces are critical parts of shell syntax; there are places where they're required (like between [[ and -e -- and also -e and the filename, and the filename and ]]), and places where they're not allowed (like around the = in an assignment), but very few places where they're optional. When copying an example, be sure to copy the spacing along with everything else.
Or in other words: shell scripts work with words. 2 words are usually separated by any number of space, tabs or linefeeds. quotes are used to create words with included spaces/tabs. So [[-e is one word without special meaning. I contrast, [[ -e are 2 words. [[ opens a condition test mode and -e is a condition that accepts the next word as param.

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.