0

I have Windows operating system. I am using GIT BASH. I have written script run.sh and run it in this way:

$ ./run.sh

This code works correctly:

dir="/c/Windows"
app="notepad.exe"
$dir/$app

application notepad will open as a result.


But I can't run the following code:

dir="/c/Program Files/7-Zip"
app="7zFM.exe"
$dir/$app

as a result a get an error message:

./run.sh: line 63: /c/Program: No such file or directory

I try this:

dir='/c/"Program Files"/7-Zip'
app="7zFM.exe"
$dir/$app

as a result:

./run.sh: line 63: /c/"Program: No such file or directory

Then i try this:

dir=/c/Program\ Files/7-Zip
app="7zFM.exe"
$dir/$app

also error:

./run.sh: line 63: /c/Program: No such file or directory

How can i use space in directory name in GIT BASH ?

1

1 Answer 1

1

Unrelated question, but the answer is to the point - c.f. Replace String in variable using bash

Short answer - always quote your variables unless you know WHY you shouldn't in a specific circumstance.

$dir/$app       # doesn't work: /c/Program: No such file or directory
"$dir/$app"     # works fine
"$dir"/"$app"   # works fine

You can also combine them.

p="$dir/$app"   # assignment works
$p              # doesn't work: /c/Program: No such file or directory
"$p"            # works fine.

You have to protect the embedded space when it's being used.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.