0

So I want to curl home brew from a bash script I made, but when I put it as condition it marks me the following error:

line 3: [/usr/bin/ruby: No such file or directory

But when I put it outside of the if statement and execute the script, it actually works.
This is my code:

#!/bin/bash

if [/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"]
then
    #if curled then do stuff here
fi

Anyone knows why it doesn't locates the file?

  • Spaces matter. `[/usr/bin/ruby` indeed doesn't exist -- you probably don't even have a directory named `[`, much less a directory named `[/usr` with a subdirectory `bin` in it. Note that `[` is not part of the syntax for using `if`; if you want to test whether a `ruby` command succeeds or not, just `if ruby ...; then` will do, with no `[` command (and yes, `[` *is the name of a command*) involved at all. – Charles Duffy Feb 14 '18 at 18:00
  • This is, by the way, one argument for why it's better teach people to spell out `test` rather than using that command's shorthand name `[`. Folks don't tend to make the same mistake of leaving out syntactically-significant spaces when typing `if test -e foo` that they do with `if [ -e foo ]`, even though `[` is a command just the same as `test` is (and `/usr/bin/[` is generally a link to the same storage on disk as `/usr/bin/test`). – Charles Duffy Feb 14 '18 at 18:03
  • @CharlesDuffy wow, you cleared a lot of doubts I had. Thanks a lot! – Aaron Garcia Feb 14 '18 at 18:12

0 Answers0