Aliases in subshell / child processMacVim behaving strangely with my aliases (even setting shell=/bin/bash...
Was the Stack Exchange "Happy April Fools" page fitting with the '90's code?
What do you call someone who asks many questions?
What Exploit Are These User Agents Trying to Use?
Getting extremely large arrows with tikzcd
Pact of Blade Warlock with Dancing Blade
Does the Idaho Potato Commission associate potato skins with healthy eating?
What does the same-ish mean?
What is the most common color to indicate the input-field is disabled?
In the UK, is it possible to get a referendum by a court decision?
Unlock My Phone! February 2018
Bullying boss launched a smear campaign and made me unemployable
What historical events would have to change in order to make 19th century "steampunk" technology possible?
Are British MPs missing the point, with these 'Indicative Votes'?
What is "[.exe" file - Cygwin shell on Windows 10
Is it possible to map the firing of neurons in the human brain so as to stimulate artificial memories in someone else?
What is the fastest integer factorization to break RSA?
Should I tell management that I intend to leave due to bad software development practices?
Why do I get negative height?
Send out email when Apex Queueable fails and test it
Standard deduction V. mortgage interest deduction - is it basically only for the rich?
Does Dispel Magic work on Tiny Hut?
Can a virus destroy the BIOS of a modern computer?
Notepad++ delete until colon for every line with replace all
What is the opposite of "eschatology"?
Aliases in subshell / child process
MacVim behaving strangely with my aliases (even setting shell=/bin/bash -l)How to run a command in a process that is not a child of the current process?How to make bash aliases available as linux commands?how to edit aliasesWhat's the rule on using the word “git” as an alias?ZSH Cull Old AliasesHow to save user made zsh shell functions and aliasesUnderstanding /etc/aliasesHow to run aliases under tmux without root privilegeWhy Unix child processes inherit [most] parent process attributes
I set up aliases in /etc/profile.d/alias.sh for each login shell. But if I run script.sh, I can't use that alias. How can I set alias even for subshells or child processes ?
/etc/profile.d/alias.sh
alias rmvr='rm -rv';
alias cprv='cp -rv';
alias mvrv='mv -rv';
linux shell alias
add a comment |
I set up aliases in /etc/profile.d/alias.sh for each login shell. But if I run script.sh, I can't use that alias. How can I set alias even for subshells or child processes ?
/etc/profile.d/alias.sh
alias rmvr='rm -rv';
alias cprv='cp -rv';
alias mvrv='mv -rv';
linux shell alias
add a comment |
I set up aliases in /etc/profile.d/alias.sh for each login shell. But if I run script.sh, I can't use that alias. How can I set alias even for subshells or child processes ?
/etc/profile.d/alias.sh
alias rmvr='rm -rv';
alias cprv='cp -rv';
alias mvrv='mv -rv';
linux shell alias
I set up aliases in /etc/profile.d/alias.sh for each login shell. But if I run script.sh, I can't use that alias. How can I set alias even for subshells or child processes ?
/etc/profile.d/alias.sh
alias rmvr='rm -rv';
alias cprv='cp -rv';
alias mvrv='mv -rv';
linux shell alias
linux shell alias
asked Aug 5 '11 at 15:54
lisaklisak
180118
180118
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Aliases are not inherited. That's why they are traditionally set in bashrc and not profile. Source your script.sh from your .bashrc or the system-wide one instead.
By inhereted, you mean that for instance exported variables are inherited and the rest is not ?
– lisak
Aug 5 '11 at 16:03
1
I don't think that .bashrc helps... If you use that alias then in a subshell, it doesn't know it
– lisak
Aug 5 '11 at 16:06
bashrc is read for all interactive non-login shells which is why this should work since most shells you start up are interactive non-login shells, and aliases do work in subshells with()
– jw013
Aug 5 '11 at 16:12
I didn't know about aliasName() invocation, thank you
– lisak
Aug 5 '11 at 16:18
Just to be clear, what I meant was in bash,alias foo='echo foobar', enter,(foo)outputsfoobar.
– jw013
Aug 5 '11 at 16:21
add a comment |
It is because /etc/profile.d/ is used only by interactive login shell. However, /etc/bash.bashrc is used by interactive non-login shell.
As I usually do set some global aliases for system, I have started to create /etc/bashrc.d where I can drop a file with some global aliases:
HAVE_BASHRC_D=`cat /etc/bash.bashrc | grep -F '/etc/bashrc.d' | wc -l`
if [ ! -d /etc/bashrc.d ]; then
mkdir -p /etc/bashrc.d
fi
if [ "$HAVE_BASHRC_D" == "0" ]; then
echo "Setting up bash aliases"
(cat <<-'EOF'
if [ -d /etc/bashrc.d ]; then
for i in /etc/bashrc.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
EOF
) >> /etc/bash.bashrc
fi
add a comment |
If you want them to be inherited to sub-shells, use functions instead. Those can be exported to the environment (export -f), and sub-shells will then have those functions defined.
So, for one of your examples:
rmvr() { rm -rv "$@"; }
export -f rmvr
If you have a bunch of them, then set for export first:
set -a # export the following funcs
rmvr() { rm -rv "$@"; }
cpvr() { cp -rv "$@"; }
mvrv() { mv -rv "$@"; }
set +a # stop exporting
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fsuperuser.com%2fquestions%2f319538%2faliases-in-subshell-child-process%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Aliases are not inherited. That's why they are traditionally set in bashrc and not profile. Source your script.sh from your .bashrc or the system-wide one instead.
By inhereted, you mean that for instance exported variables are inherited and the rest is not ?
– lisak
Aug 5 '11 at 16:03
1
I don't think that .bashrc helps... If you use that alias then in a subshell, it doesn't know it
– lisak
Aug 5 '11 at 16:06
bashrc is read for all interactive non-login shells which is why this should work since most shells you start up are interactive non-login shells, and aliases do work in subshells with()
– jw013
Aug 5 '11 at 16:12
I didn't know about aliasName() invocation, thank you
– lisak
Aug 5 '11 at 16:18
Just to be clear, what I meant was in bash,alias foo='echo foobar', enter,(foo)outputsfoobar.
– jw013
Aug 5 '11 at 16:21
add a comment |
Aliases are not inherited. That's why they are traditionally set in bashrc and not profile. Source your script.sh from your .bashrc or the system-wide one instead.
By inhereted, you mean that for instance exported variables are inherited and the rest is not ?
– lisak
Aug 5 '11 at 16:03
1
I don't think that .bashrc helps... If you use that alias then in a subshell, it doesn't know it
– lisak
Aug 5 '11 at 16:06
bashrc is read for all interactive non-login shells which is why this should work since most shells you start up are interactive non-login shells, and aliases do work in subshells with()
– jw013
Aug 5 '11 at 16:12
I didn't know about aliasName() invocation, thank you
– lisak
Aug 5 '11 at 16:18
Just to be clear, what I meant was in bash,alias foo='echo foobar', enter,(foo)outputsfoobar.
– jw013
Aug 5 '11 at 16:21
add a comment |
Aliases are not inherited. That's why they are traditionally set in bashrc and not profile. Source your script.sh from your .bashrc or the system-wide one instead.
Aliases are not inherited. That's why they are traditionally set in bashrc and not profile. Source your script.sh from your .bashrc or the system-wide one instead.
answered Aug 5 '11 at 15:59
jw013jw013
1,108614
1,108614
By inhereted, you mean that for instance exported variables are inherited and the rest is not ?
– lisak
Aug 5 '11 at 16:03
1
I don't think that .bashrc helps... If you use that alias then in a subshell, it doesn't know it
– lisak
Aug 5 '11 at 16:06
bashrc is read for all interactive non-login shells which is why this should work since most shells you start up are interactive non-login shells, and aliases do work in subshells with()
– jw013
Aug 5 '11 at 16:12
I didn't know about aliasName() invocation, thank you
– lisak
Aug 5 '11 at 16:18
Just to be clear, what I meant was in bash,alias foo='echo foobar', enter,(foo)outputsfoobar.
– jw013
Aug 5 '11 at 16:21
add a comment |
By inhereted, you mean that for instance exported variables are inherited and the rest is not ?
– lisak
Aug 5 '11 at 16:03
1
I don't think that .bashrc helps... If you use that alias then in a subshell, it doesn't know it
– lisak
Aug 5 '11 at 16:06
bashrc is read for all interactive non-login shells which is why this should work since most shells you start up are interactive non-login shells, and aliases do work in subshells with()
– jw013
Aug 5 '11 at 16:12
I didn't know about aliasName() invocation, thank you
– lisak
Aug 5 '11 at 16:18
Just to be clear, what I meant was in bash,alias foo='echo foobar', enter,(foo)outputsfoobar.
– jw013
Aug 5 '11 at 16:21
By inhereted, you mean that for instance exported variables are inherited and the rest is not ?
– lisak
Aug 5 '11 at 16:03
By inhereted, you mean that for instance exported variables are inherited and the rest is not ?
– lisak
Aug 5 '11 at 16:03
1
1
I don't think that .bashrc helps... If you use that alias then in a subshell, it doesn't know it
– lisak
Aug 5 '11 at 16:06
I don't think that .bashrc helps... If you use that alias then in a subshell, it doesn't know it
– lisak
Aug 5 '11 at 16:06
bashrc is read for all interactive non-login shells which is why this should work since most shells you start up are interactive non-login shells, and aliases do work in subshells with
()– jw013
Aug 5 '11 at 16:12
bashrc is read for all interactive non-login shells which is why this should work since most shells you start up are interactive non-login shells, and aliases do work in subshells with
()– jw013
Aug 5 '11 at 16:12
I didn't know about aliasName() invocation, thank you
– lisak
Aug 5 '11 at 16:18
I didn't know about aliasName() invocation, thank you
– lisak
Aug 5 '11 at 16:18
Just to be clear, what I meant was in bash,
alias foo='echo foobar', enter, (foo) outputs foobar.– jw013
Aug 5 '11 at 16:21
Just to be clear, what I meant was in bash,
alias foo='echo foobar', enter, (foo) outputs foobar.– jw013
Aug 5 '11 at 16:21
add a comment |
It is because /etc/profile.d/ is used only by interactive login shell. However, /etc/bash.bashrc is used by interactive non-login shell.
As I usually do set some global aliases for system, I have started to create /etc/bashrc.d where I can drop a file with some global aliases:
HAVE_BASHRC_D=`cat /etc/bash.bashrc | grep -F '/etc/bashrc.d' | wc -l`
if [ ! -d /etc/bashrc.d ]; then
mkdir -p /etc/bashrc.d
fi
if [ "$HAVE_BASHRC_D" == "0" ]; then
echo "Setting up bash aliases"
(cat <<-'EOF'
if [ -d /etc/bashrc.d ]; then
for i in /etc/bashrc.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
EOF
) >> /etc/bash.bashrc
fi
add a comment |
It is because /etc/profile.d/ is used only by interactive login shell. However, /etc/bash.bashrc is used by interactive non-login shell.
As I usually do set some global aliases for system, I have started to create /etc/bashrc.d where I can drop a file with some global aliases:
HAVE_BASHRC_D=`cat /etc/bash.bashrc | grep -F '/etc/bashrc.d' | wc -l`
if [ ! -d /etc/bashrc.d ]; then
mkdir -p /etc/bashrc.d
fi
if [ "$HAVE_BASHRC_D" == "0" ]; then
echo "Setting up bash aliases"
(cat <<-'EOF'
if [ -d /etc/bashrc.d ]; then
for i in /etc/bashrc.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
EOF
) >> /etc/bash.bashrc
fi
add a comment |
It is because /etc/profile.d/ is used only by interactive login shell. However, /etc/bash.bashrc is used by interactive non-login shell.
As I usually do set some global aliases for system, I have started to create /etc/bashrc.d where I can drop a file with some global aliases:
HAVE_BASHRC_D=`cat /etc/bash.bashrc | grep -F '/etc/bashrc.d' | wc -l`
if [ ! -d /etc/bashrc.d ]; then
mkdir -p /etc/bashrc.d
fi
if [ "$HAVE_BASHRC_D" == "0" ]; then
echo "Setting up bash aliases"
(cat <<-'EOF'
if [ -d /etc/bashrc.d ]; then
for i in /etc/bashrc.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
EOF
) >> /etc/bash.bashrc
fi
It is because /etc/profile.d/ is used only by interactive login shell. However, /etc/bash.bashrc is used by interactive non-login shell.
As I usually do set some global aliases for system, I have started to create /etc/bashrc.d where I can drop a file with some global aliases:
HAVE_BASHRC_D=`cat /etc/bash.bashrc | grep -F '/etc/bashrc.d' | wc -l`
if [ ! -d /etc/bashrc.d ]; then
mkdir -p /etc/bashrc.d
fi
if [ "$HAVE_BASHRC_D" == "0" ]; then
echo "Setting up bash aliases"
(cat <<-'EOF'
if [ -d /etc/bashrc.d ]; then
for i in /etc/bashrc.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
EOF
) >> /etc/bash.bashrc
fi
edited Nov 8 '11 at 20:43
Simon Sheehan
7,715124269
7,715124269
answered Nov 8 '11 at 19:35
atusatus
8111
8111
add a comment |
add a comment |
If you want them to be inherited to sub-shells, use functions instead. Those can be exported to the environment (export -f), and sub-shells will then have those functions defined.
So, for one of your examples:
rmvr() { rm -rv "$@"; }
export -f rmvr
If you have a bunch of them, then set for export first:
set -a # export the following funcs
rmvr() { rm -rv "$@"; }
cpvr() { cp -rv "$@"; }
mvrv() { mv -rv "$@"; }
set +a # stop exporting
add a comment |
If you want them to be inherited to sub-shells, use functions instead. Those can be exported to the environment (export -f), and sub-shells will then have those functions defined.
So, for one of your examples:
rmvr() { rm -rv "$@"; }
export -f rmvr
If you have a bunch of them, then set for export first:
set -a # export the following funcs
rmvr() { rm -rv "$@"; }
cpvr() { cp -rv "$@"; }
mvrv() { mv -rv "$@"; }
set +a # stop exporting
add a comment |
If you want them to be inherited to sub-shells, use functions instead. Those can be exported to the environment (export -f), and sub-shells will then have those functions defined.
So, for one of your examples:
rmvr() { rm -rv "$@"; }
export -f rmvr
If you have a bunch of them, then set for export first:
set -a # export the following funcs
rmvr() { rm -rv "$@"; }
cpvr() { cp -rv "$@"; }
mvrv() { mv -rv "$@"; }
set +a # stop exporting
If you want them to be inherited to sub-shells, use functions instead. Those can be exported to the environment (export -f), and sub-shells will then have those functions defined.
So, for one of your examples:
rmvr() { rm -rv "$@"; }
export -f rmvr
If you have a bunch of them, then set for export first:
set -a # export the following funcs
rmvr() { rm -rv "$@"; }
cpvr() { cp -rv "$@"; }
mvrv() { mv -rv "$@"; }
set +a # stop exporting
answered 2 hours ago
DrojDroj
20124
20124
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f319538%2faliases-in-subshell-child-process%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