1

I want to open a application using shell script.

But! when file name has space, script read this as two files.

1 path=/Applications
2 program=/Google Chrome.app    
3 open $path$program

it's not working...

when I use alias like these...

program="/Google Chrome.app" or
program=/Google\ Chrome.app  or
program="/Google\ Chrome.app"  

shell cognized two files like this

"The files /Applications/Google and /current_dir/Chrome.app do not exist."

How I fix that? please give me your teaching

LinFelix
  • 1,026
  • 1
  • 13
  • 23
woojlee
  • 11
  • 1
  • 4
    `open "$path/$program"` – jordanm May 03 '22 at 14:36
  • 2
    See ["When should I wrap quotes around a shell variable?"](https://stackoverflow.com/questions/10067266/when-should-i-wrap-quotes-around-a-shell-variable) (short answer: almost always). – Gordon Davisson May 03 '22 at 17:05
  • 1
    You have tagged the question by _bash_ or by _zsh_ . Which shell are you interested in? If you need to know this for both shells, ask two questions (because bash and zsh are a bit different in this respect. – user1934428 May 04 '22 at 09:07
  • _when I use alias like these_ : There is no alias in the code you provided. `program` is a _shell variable_. – user1934428 May 04 '22 at 09:08

1 Answers1

0

You can wrap your variables in quotes. So what you can do is:

path=Applications
program="Google Chrome.app"
open /$path/$program
LinFelix
  • 1,026
  • 1
  • 13
  • 23