Reputation: 1
I recently got entangled by the UNIX file system and was playing around with terminal. I noticed that however I changed my $PATH variable, running "Google Chrome", the executable for opening up the Chrome Window, gives me error message of
-bash: Google Chrome: command not found
Here's the context: Google is installed on my /Applications/Google Chrome.app/Contents/MacOS as an executable called "Google Chrome" (I know that because when I type
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
a new Chrome window pops out with an error message saying
[12838:35843:0822/170630.283203:ERROR:browser_gpu_channel_host_factory.cc(103)] Failed to launch GPU process.
so I'm pretty sure this is the executable for running the program)
Then I did a little digging on $PATH variable which is supposed to maintain the searching path of where to find the executables everytime I type a "command" (or exe doesnt matter). Therefore, I went to ~ and find the file called .bash_profile where $PATH is edited and stored and append this to the file:
PATH="/Applications/Google\ Chrome.app/Contents/MacOS:${PATH}" export PATH
Then I source ~/.bash_profile and echo $PATH to that indeed the directory containing Chrome executable is inserted as part of $PATH as follow:
> echo $PATH
/Applications/Google\ Chrome.app/Contents/MacOS:/Library/Frameworks/Python.framework/Versions/3.6/bin: ...
Then when I type Google\ Chrome, the system responds with "command not found". I went further more to do whereis Google\ Chrome and which Google\ Chrome, yet I got no response that forces me to believe Google Chrome is not the among the executing path.
Here's question, what did I do wrong when trying to edit $PATH to make Chrome easier to access? Is it because the way I understand $PATH is wrong? Or is it because I miss some tiny details? As far I know, I should have Chrome running as other applications like python and cassandra with the same $PATH edit but I didn't. Please share your precious insights with me on the topic. Your time and effort is very much appreciated :)
Upvotes: 0
Views: 3146
Reputation: 295272
What you did wrong was putting the backslash into the variable as a literal; this has the shell trying to find a directory with a backslash in its name. (Because the backslash is present in the output of echo
, we know that it actually ended up in the final variable, rather than being recognized as an effectively meaningless sequence and discarded).
Inside quotes, the space is already known to be literal, so there's no point to an additional backslash;
PATH="/Applications/Google Chrome.app/Contents/MacOS:$PATH"
...will suffice. (There's no need to explicitly export
: Updating any shell variable named identically to a preexisting environment variable will automatically alter the latter).
By the way -- if you want to define a shell function so you can call chrome http://example.com/
, that might look like:
chrome() { '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' "$@"; }
Unlike aliases, functions can be exported (export -f chrome
) to make them available to other instances of bash; they're also able to perform logic (such as inspecting their arguments and having different behaviors based on what they're passed).
Upvotes: 1