Handling whitespace in filepaths
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have this:
muh_dir=`cd $(dirname "$BASH_SOURCE") && pwd`
and yeah I tested the above (it has backticks) and it doesn't work well with whitespace in the pwd.
On the other hand, this is better:
muh_dir="$(cd $(dirname "$BASH_SOURCE") && pwd)"
My question is - this adds 3 chars to my command the syntax changes in my editor. The first way is much nicer..is there anyway to handle whitespace with the shorter syntax or do I just bite the bullet?
bash shell-script shell
add a comment |Â
up vote
0
down vote
favorite
I have this:
muh_dir=`cd $(dirname "$BASH_SOURCE") && pwd`
and yeah I tested the above (it has backticks) and it doesn't work well with whitespace in the pwd.
On the other hand, this is better:
muh_dir="$(cd $(dirname "$BASH_SOURCE") && pwd)"
My question is - this adds 3 chars to my command the syntax changes in my editor. The first way is much nicer..is there anyway to handle whitespace with the shorter syntax or do I just bite the bullet?
bash shell-script shell
Please see Why does my shell script choke on whitespace or other special characters? and Have backticks (i.e.`cmd`
) in *sh shells been deprecated?
â Wildcard
9 mins ago
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have this:
muh_dir=`cd $(dirname "$BASH_SOURCE") && pwd`
and yeah I tested the above (it has backticks) and it doesn't work well with whitespace in the pwd.
On the other hand, this is better:
muh_dir="$(cd $(dirname "$BASH_SOURCE") && pwd)"
My question is - this adds 3 chars to my command the syntax changes in my editor. The first way is much nicer..is there anyway to handle whitespace with the shorter syntax or do I just bite the bullet?
bash shell-script shell
I have this:
muh_dir=`cd $(dirname "$BASH_SOURCE") && pwd`
and yeah I tested the above (it has backticks) and it doesn't work well with whitespace in the pwd.
On the other hand, this is better:
muh_dir="$(cd $(dirname "$BASH_SOURCE") && pwd)"
My question is - this adds 3 chars to my command the syntax changes in my editor. The first way is much nicer..is there anyway to handle whitespace with the shorter syntax or do I just bite the bullet?
bash shell-script shell
bash shell-script shell
edited 8 mins ago
asked 13 mins ago
Alexander Mills
2,0871234
2,0871234
Please see Why does my shell script choke on whitespace or other special characters? and Have backticks (i.e.`cmd`
) in *sh shells been deprecated?
â Wildcard
9 mins ago
add a comment |Â
Please see Why does my shell script choke on whitespace or other special characters? and Have backticks (i.e.`cmd`
) in *sh shells been deprecated?
â Wildcard
9 mins ago
Please see Why does my shell script choke on whitespace or other special characters? and Have backticks (i.e.
`cmd`
) in *sh shells been deprecated?â Wildcard
9 mins ago
Please see Why does my shell script choke on whitespace or other special characters? and Have backticks (i.e.
`cmd`
) in *sh shells been deprecated?â Wildcard
9 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
Understand quotes, then Use More Quotesâ¢. It really is the simplest thing you can do that will work.
As an aside, the most important property of any code is its maintainability. The number of characters is only very weakly correlated to maintainability - adding three characters to 45 (6.7% increase) to handle spaces doesn't even remotely trigger my code nose.
this is so loco it hurts so much lulz
â Alexander Mills
9 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Understand quotes, then Use More Quotesâ¢. It really is the simplest thing you can do that will work.
As an aside, the most important property of any code is its maintainability. The number of characters is only very weakly correlated to maintainability - adding three characters to 45 (6.7% increase) to handle spaces doesn't even remotely trigger my code nose.
this is so loco it hurts so much lulz
â Alexander Mills
9 mins ago
add a comment |Â
up vote
1
down vote
Understand quotes, then Use More Quotesâ¢. It really is the simplest thing you can do that will work.
As an aside, the most important property of any code is its maintainability. The number of characters is only very weakly correlated to maintainability - adding three characters to 45 (6.7% increase) to handle spaces doesn't even remotely trigger my code nose.
this is so loco it hurts so much lulz
â Alexander Mills
9 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Understand quotes, then Use More Quotesâ¢. It really is the simplest thing you can do that will work.
As an aside, the most important property of any code is its maintainability. The number of characters is only very weakly correlated to maintainability - adding three characters to 45 (6.7% increase) to handle spaces doesn't even remotely trigger my code nose.
Understand quotes, then Use More Quotesâ¢. It really is the simplest thing you can do that will work.
As an aside, the most important property of any code is its maintainability. The number of characters is only very weakly correlated to maintainability - adding three characters to 45 (6.7% increase) to handle spaces doesn't even remotely trigger my code nose.
edited 8 mins ago
answered 10 mins ago
l0b0
27k17108236
27k17108236
this is so loco it hurts so much lulz
â Alexander Mills
9 mins ago
add a comment |Â
this is so loco it hurts so much lulz
â Alexander Mills
9 mins ago
this is so loco it hurts so much lulz
â Alexander Mills
9 mins ago
this is so loco it hurts so much lulz
â Alexander Mills
9 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f479267%2fhandling-whitespace-in-filepaths%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Please see Why does my shell script choke on whitespace or other special characters? and Have backticks (i.e.
`cmd`
) in *sh shells been deprecated?â Wildcard
9 mins ago