BASH: how can I save the exit code in PS1 in order to use it later in PS1?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am attempting to customize my PS1, in the following way (I have removed the colours):
PS1='u@h:w$(git_branch)$(useExitCode)$ '
where
git_branch()
sed -e '/^[^*]/d' -e 's/* (.*)/(1)/'
As for exit status, I would like to pick it up before the git_branch
function is executed, and use it in useExitCode
. How can I do that? The latter function could look like this:
useExitCode()
local exitCode=$1
if [[ $exitCode == 0 ]]; then
echo ':)'
else
echo ':('
fi
The question is, how can I store the exitcode in PS1 and use it later ?
Something like the following does not work, but gives an idea of the geenral direction:
PS1='exitCode=$?u@h:w$(git_branch)$(useExitCode $exitCode)$ '
The above echo's the "exitCode=0" (or =1) part but it is not stored, so it is empty at its invocation "$exitCode" later.
Thank you in advance for your help
prompt bashrc exit-code ps1
add a comment |Â
up vote
0
down vote
favorite
I am attempting to customize my PS1, in the following way (I have removed the colours):
PS1='u@h:w$(git_branch)$(useExitCode)$ '
where
git_branch()
sed -e '/^[^*]/d' -e 's/* (.*)/(1)/'
As for exit status, I would like to pick it up before the git_branch
function is executed, and use it in useExitCode
. How can I do that? The latter function could look like this:
useExitCode()
local exitCode=$1
if [[ $exitCode == 0 ]]; then
echo ':)'
else
echo ':('
fi
The question is, how can I store the exitcode in PS1 and use it later ?
Something like the following does not work, but gives an idea of the geenral direction:
PS1='exitCode=$?u@h:w$(git_branch)$(useExitCode $exitCode)$ '
The above echo's the "exitCode=0" (or =1) part but it is not stored, so it is empty at its invocation "$exitCode" later.
Thank you in advance for your help
prompt bashrc exit-code ps1
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am attempting to customize my PS1, in the following way (I have removed the colours):
PS1='u@h:w$(git_branch)$(useExitCode)$ '
where
git_branch()
sed -e '/^[^*]/d' -e 's/* (.*)/(1)/'
As for exit status, I would like to pick it up before the git_branch
function is executed, and use it in useExitCode
. How can I do that? The latter function could look like this:
useExitCode()
local exitCode=$1
if [[ $exitCode == 0 ]]; then
echo ':)'
else
echo ':('
fi
The question is, how can I store the exitcode in PS1 and use it later ?
Something like the following does not work, but gives an idea of the geenral direction:
PS1='exitCode=$?u@h:w$(git_branch)$(useExitCode $exitCode)$ '
The above echo's the "exitCode=0" (or =1) part but it is not stored, so it is empty at its invocation "$exitCode" later.
Thank you in advance for your help
prompt bashrc exit-code ps1
I am attempting to customize my PS1, in the following way (I have removed the colours):
PS1='u@h:w$(git_branch)$(useExitCode)$ '
where
git_branch()
sed -e '/^[^*]/d' -e 's/* (.*)/(1)/'
As for exit status, I would like to pick it up before the git_branch
function is executed, and use it in useExitCode
. How can I do that? The latter function could look like this:
useExitCode()
local exitCode=$1
if [[ $exitCode == 0 ]]; then
echo ':)'
else
echo ':('
fi
The question is, how can I store the exitcode in PS1 and use it later ?
Something like the following does not work, but gives an idea of the geenral direction:
PS1='exitCode=$?u@h:w$(git_branch)$(useExitCode $exitCode)$ '
The above echo's the "exitCode=0" (or =1) part but it is not stored, so it is empty at its invocation "$exitCode" later.
Thank you in advance for your help
prompt bashrc exit-code ps1
prompt bashrc exit-code ps1
asked 3 mins ago
nass
66321431
66321431
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f477848%2fbash-how-can-i-save-the-exit-code-in-ps1-in-order-to-use-it-later-in-ps1%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