Why are backslashes included in this shell script?Run a command that is shadowed by an aliasWhy escape trivial characters in shell script?Is there any reason to escape a dot in a bash filename expansion?How do you use variables with values containing spaces in a Z-shell (zsh) script command?Why does commenting out this line in a shell script (using pdftk) cause problems?log out via shell scriptIs there a function in shell script equivalent a var_dump(PHP)Why does number of backslashes increase in strace as opposed to being reduced by bash rules?What does backslash dot mean as a command?Why does this 'while' loop not recognize the last line?how do i add the creation of a directory to this cli command
Why is it bad to use your whole foot in rock climbing
Are athlete's college degrees discounted by employers and graduate school admissions?
Is Jesus the last Prophet?
How do I type a hyphen in iOS 12?
What does this line mean in Zelazny's The Courts of Chaos?
How to represent jealousy in a cute way?
ISP is not hashing the password I log in with online. Should I take any action?
How to deal with an excess of white-space in a CRM UI?
If absolute velocity does not exist, how can we say a rocket accelerates in empty space?
Which are the methodologies for interpreting Vedas?
Can I get a photo of an Ancient Arrow?
Can a 40amp breaker be used safely and without issue with a 40amp device on 6AWG wire?
What is the language spoken in Babylon?
Keeping track of theme when improvising
Does scarcity apply only to commodities?
The best in flight meal option for those suffering from reflux
In American Politics, why is the Justice Department under the President?
Did I need a visa in 2004 and 2006?
Is the first of the 10 Commandments considered a mitzvah?
What do you call the action of "describing events as they happen" like sports anchors do?
A life of PhD: is it feasible?
In The Incredibles 2, why does Screenslaver's name use a pun on something that doesn't exist in the 1950s pastiche?
Am I being scammed by a sugar daddy?
Does the UK delegate some immigration control to the Republic of Ireland?
Why are backslashes included in this shell script?
Run a command that is shadowed by an aliasWhy escape trivial characters in shell script?Is there any reason to escape a dot in a bash filename expansion?How do you use variables with values containing spaces in a Z-shell (zsh) script command?Why does commenting out this line in a shell script (using pdftk) cause problems?log out via shell scriptIs there a function in shell script equivalent a var_dump(PHP)Why does number of backslashes increase in strace as opposed to being reduced by bash rules?What does backslash dot mean as a command?Why does this 'while' loop not recognize the last line?how do i add the creation of a directory to this cli command
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
In my copy of the conda.sh
script, I see the following lines:
if [ -n "$_CE_CONDA" ] && [ -n "$WINDIR+x" ]; then
SYSP=$(dirname "$CONDA_EXE")
else
SYSP=$(dirname "$CONDA_EXE")
SYSP=$(dirname "$SYSP")
fi
I am curious as to why there is a backslash in front the the d
in dirname
. I do not believe it is necessary. This use of backslashes also appears in other places in the source file. Is there a reason for doing this that I am missing?
bash shell-script
add a comment |
In my copy of the conda.sh
script, I see the following lines:
if [ -n "$_CE_CONDA" ] && [ -n "$WINDIR+x" ]; then
SYSP=$(dirname "$CONDA_EXE")
else
SYSP=$(dirname "$CONDA_EXE")
SYSP=$(dirname "$SYSP")
fi
I am curious as to why there is a backslash in front the the d
in dirname
. I do not believe it is necessary. This use of backslashes also appears in other places in the source file. Is there a reason for doing this that I am missing?
bash shell-script
1
Related: Run a command that is shadowed by an alias
– steeldriver
7 hours ago
add a comment |
In my copy of the conda.sh
script, I see the following lines:
if [ -n "$_CE_CONDA" ] && [ -n "$WINDIR+x" ]; then
SYSP=$(dirname "$CONDA_EXE")
else
SYSP=$(dirname "$CONDA_EXE")
SYSP=$(dirname "$SYSP")
fi
I am curious as to why there is a backslash in front the the d
in dirname
. I do not believe it is necessary. This use of backslashes also appears in other places in the source file. Is there a reason for doing this that I am missing?
bash shell-script
In my copy of the conda.sh
script, I see the following lines:
if [ -n "$_CE_CONDA" ] && [ -n "$WINDIR+x" ]; then
SYSP=$(dirname "$CONDA_EXE")
else
SYSP=$(dirname "$CONDA_EXE")
SYSP=$(dirname "$SYSP")
fi
I am curious as to why there is a backslash in front the the d
in dirname
. I do not believe it is necessary. This use of backslashes also appears in other places in the source file. Is there a reason for doing this that I am missing?
bash shell-script
bash shell-script
asked 8 hours ago
extremeaxe5extremeaxe5
26618
26618
1
Related: Run a command that is shadowed by an alias
– steeldriver
7 hours ago
add a comment |
1
Related: Run a command that is shadowed by an alias
– steeldriver
7 hours ago
1
1
Related: Run a command that is shadowed by an alias
– steeldriver
7 hours ago
Related: Run a command that is shadowed by an alias
– steeldriver
7 hours ago
add a comment |
2 Answers
2
active
oldest
votes
If conda.sh
is a file meant to be sourced, then the backslashes are for bypassing aliases. Bash typically disables alias expansion for script execution, but for sourced files, which may run in interactive shells, that's not the case. So just dirname
may run an alias named dirname
, but dirname
will skip alias expansion and run a function or command named dirname
. (Not just backslashes, though, any quoting will do.)
1
Orcommand dirname
.
– Kusalananda♦
8 hours ago
add a comment |
Backslash will suppress alias expansion, ie it executes the original command and makes sure that alias version does not run. Scripts can unknowingly run with alias expansion when the system has set shopt -s expand_aliases
(BASH only) or if it is executed using source
.
./conda.sh # usually no alias expansion (unless `shopt -s expand_aliases` in BASH)
source ./conda.sh # alias expansion
. ./conda.sh # alias expansion
Some sysadmins like to put backslash in everything as a preventive measure against side-effects of aliases, just in case it was aliased unintentionally somewhere else and the alias gets expanded as explained previously. For example, if the system has set this alias dirname='dirname -z'
somewhere and the condition allows the alias to be expanded, then a script that tries to call dirname will unfortunately call dirname -z
instead, which was not the script intended.
If there's certainty that such alias do not exist, we can remove all the backslash and it should work fine.
Alternatively, one can use command
instead of backslash version to suppress alias. Thus, instead of dirname
, one can use command dirname
, which might look more readable. (For built-in commands like cd
, one should use builtin
instead). I prefer this instead, as it also bypasses function with same name as well as any aliases.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f524254%2fwhy-are-backslashes-included-in-this-shell-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If conda.sh
is a file meant to be sourced, then the backslashes are for bypassing aliases. Bash typically disables alias expansion for script execution, but for sourced files, which may run in interactive shells, that's not the case. So just dirname
may run an alias named dirname
, but dirname
will skip alias expansion and run a function or command named dirname
. (Not just backslashes, though, any quoting will do.)
1
Orcommand dirname
.
– Kusalananda♦
8 hours ago
add a comment |
If conda.sh
is a file meant to be sourced, then the backslashes are for bypassing aliases. Bash typically disables alias expansion for script execution, but for sourced files, which may run in interactive shells, that's not the case. So just dirname
may run an alias named dirname
, but dirname
will skip alias expansion and run a function or command named dirname
. (Not just backslashes, though, any quoting will do.)
1
Orcommand dirname
.
– Kusalananda♦
8 hours ago
add a comment |
If conda.sh
is a file meant to be sourced, then the backslashes are for bypassing aliases. Bash typically disables alias expansion for script execution, but for sourced files, which may run in interactive shells, that's not the case. So just dirname
may run an alias named dirname
, but dirname
will skip alias expansion and run a function or command named dirname
. (Not just backslashes, though, any quoting will do.)
If conda.sh
is a file meant to be sourced, then the backslashes are for bypassing aliases. Bash typically disables alias expansion for script execution, but for sourced files, which may run in interactive shells, that's not the case. So just dirname
may run an alias named dirname
, but dirname
will skip alias expansion and run a function or command named dirname
. (Not just backslashes, though, any quoting will do.)
answered 8 hours ago
murumuru
39.3k595170
39.3k595170
1
Orcommand dirname
.
– Kusalananda♦
8 hours ago
add a comment |
1
Orcommand dirname
.
– Kusalananda♦
8 hours ago
1
1
Or
command dirname
.– Kusalananda♦
8 hours ago
Or
command dirname
.– Kusalananda♦
8 hours ago
add a comment |
Backslash will suppress alias expansion, ie it executes the original command and makes sure that alias version does not run. Scripts can unknowingly run with alias expansion when the system has set shopt -s expand_aliases
(BASH only) or if it is executed using source
.
./conda.sh # usually no alias expansion (unless `shopt -s expand_aliases` in BASH)
source ./conda.sh # alias expansion
. ./conda.sh # alias expansion
Some sysadmins like to put backslash in everything as a preventive measure against side-effects of aliases, just in case it was aliased unintentionally somewhere else and the alias gets expanded as explained previously. For example, if the system has set this alias dirname='dirname -z'
somewhere and the condition allows the alias to be expanded, then a script that tries to call dirname will unfortunately call dirname -z
instead, which was not the script intended.
If there's certainty that such alias do not exist, we can remove all the backslash and it should work fine.
Alternatively, one can use command
instead of backslash version to suppress alias. Thus, instead of dirname
, one can use command dirname
, which might look more readable. (For built-in commands like cd
, one should use builtin
instead). I prefer this instead, as it also bypasses function with same name as well as any aliases.
add a comment |
Backslash will suppress alias expansion, ie it executes the original command and makes sure that alias version does not run. Scripts can unknowingly run with alias expansion when the system has set shopt -s expand_aliases
(BASH only) or if it is executed using source
.
./conda.sh # usually no alias expansion (unless `shopt -s expand_aliases` in BASH)
source ./conda.sh # alias expansion
. ./conda.sh # alias expansion
Some sysadmins like to put backslash in everything as a preventive measure against side-effects of aliases, just in case it was aliased unintentionally somewhere else and the alias gets expanded as explained previously. For example, if the system has set this alias dirname='dirname -z'
somewhere and the condition allows the alias to be expanded, then a script that tries to call dirname will unfortunately call dirname -z
instead, which was not the script intended.
If there's certainty that such alias do not exist, we can remove all the backslash and it should work fine.
Alternatively, one can use command
instead of backslash version to suppress alias. Thus, instead of dirname
, one can use command dirname
, which might look more readable. (For built-in commands like cd
, one should use builtin
instead). I prefer this instead, as it also bypasses function with same name as well as any aliases.
add a comment |
Backslash will suppress alias expansion, ie it executes the original command and makes sure that alias version does not run. Scripts can unknowingly run with alias expansion when the system has set shopt -s expand_aliases
(BASH only) or if it is executed using source
.
./conda.sh # usually no alias expansion (unless `shopt -s expand_aliases` in BASH)
source ./conda.sh # alias expansion
. ./conda.sh # alias expansion
Some sysadmins like to put backslash in everything as a preventive measure against side-effects of aliases, just in case it was aliased unintentionally somewhere else and the alias gets expanded as explained previously. For example, if the system has set this alias dirname='dirname -z'
somewhere and the condition allows the alias to be expanded, then a script that tries to call dirname will unfortunately call dirname -z
instead, which was not the script intended.
If there's certainty that such alias do not exist, we can remove all the backslash and it should work fine.
Alternatively, one can use command
instead of backslash version to suppress alias. Thus, instead of dirname
, one can use command dirname
, which might look more readable. (For built-in commands like cd
, one should use builtin
instead). I prefer this instead, as it also bypasses function with same name as well as any aliases.
Backslash will suppress alias expansion, ie it executes the original command and makes sure that alias version does not run. Scripts can unknowingly run with alias expansion when the system has set shopt -s expand_aliases
(BASH only) or if it is executed using source
.
./conda.sh # usually no alias expansion (unless `shopt -s expand_aliases` in BASH)
source ./conda.sh # alias expansion
. ./conda.sh # alias expansion
Some sysadmins like to put backslash in everything as a preventive measure against side-effects of aliases, just in case it was aliased unintentionally somewhere else and the alias gets expanded as explained previously. For example, if the system has set this alias dirname='dirname -z'
somewhere and the condition allows the alias to be expanded, then a script that tries to call dirname will unfortunately call dirname -z
instead, which was not the script intended.
If there's certainty that such alias do not exist, we can remove all the backslash and it should work fine.
Alternatively, one can use command
instead of backslash version to suppress alias. Thus, instead of dirname
, one can use command dirname
, which might look more readable. (For built-in commands like cd
, one should use builtin
instead). I prefer this instead, as it also bypasses function with same name as well as any aliases.
answered 7 hours ago
otter.prootter.pro
513
513
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f524254%2fwhy-are-backslashes-included-in-this-shell-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Related: Run a command that is shadowed by an alias
– steeldriver
7 hours ago