0

For some strange reason, I can't make the test [[ work in a bash script

#!/bin/bash 
if [[ $DIR ~= DIRECTORY_TO_TEST ]]
then 
   ...
fi

the error message is [[: not found the bash version is 4.4.12 and the return is

user1946989
  • 377
  • 1
  • 4
  • 16
  • 3
    How are you executing the script? That sounds more like an error you would get if you execute the script with `sh` and `sh` isn't actually `bash`. – chepner Aug 02 '17 at 01:46
  • @chepner I think you right i always use sh that may simply be that – user1946989 Aug 02 '17 at 05:17
  • 1
    Don't edit "Solved" into questions here. Accept an answer to mark your question solved. If you did something other than using one of the answers someone else built, then add your own answer, then accept it. – Charles Duffy Feb 14 '18 at 19:19
  • @Charles Duffy, sorry the best answer was indeed a comment. I don't know how to accept a comment as an answer. I am trying to rework all my questions as StackOverflow doesn't let me ask any question anymore – user1946989 Feb 14 '18 at 19:23
  • 1
    Gotcha. Typically, the process is to ask the person who added the comment if they want to leave it as an answer so they get the credit, and if they don't respond, to add it yourself, referencing the comment (it's polite but not essential to use the "Community Wiki" checkbox for an answer that purely represents someone else's work, as that avoids earning rep). There's a delay before you can accept your own answers; I'd need to check the docs to know if it's shorter when upvotes are present. – Charles Duffy Feb 14 '18 at 19:40
  • Thank you, it is also similar the question you add as duplicate however the script contain the #!/bin/bash in the first line – user1946989 Feb 14 '18 at 19:48
  • @chepner please could you add your comment as an anwser – user1946989 Feb 14 '18 at 19:50
  • 1
    @user1946989, the answer to that question explicitly specifies that `sh` will override the `#!/bin/bash` shebang if used at invocation. – Charles Duffy Feb 15 '18 at 02:58

0 Answers0