When I am running an interactive bash
session, I sometimes experiment with sh
.
I call sh
directly from this bash
session.
My question is, how can I change the PS1
prompt of this subshell?
I would like the prompt to be something like sh$
, notifying me that I am using sh
and not bash
.
What I have tried so far is:
- I made a configuration file analogous to
.bashrc
named.shrc
- I put only one line in it:
export PS1='$(echo ${0})\$ '
I then modified
~/.profile
to say the following:# if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi # if running another shell else if [ -f "$HOME/.shrc" ]; then . "$HOME/.shrc" fi fi
I restarted the terminal, but the changes are not being applied.
- If I run
. ~/.shrc
insh
manually, the changes do get applied.
What am I doing wrong?
alias sh='PS1='\''$0\$ '\'' sh'
? – Stefan van den Akker Jul 30 '14 at 11:57"'"
or\'
. So what those do is close the current string like'current string'
wedges a backslash quoted hard quote in like\'
then starts a new one like'next string'
- and they all get concatenated.'string'\''string'
– mikeserv Jul 30 '14 at 12:00$0\$
part (alias sh="PS1='$0\$ ' sh"
results inbash$
), right? – Stefan van den Akker Jul 30 '14 at 12:08$PS1
is special - it iseval
ed at each prompt. So you need the shell script in there, not the expansion of the variables. Especially since when you call it on the command line, it isn't even$0
yet - that's stillbash
at that time. If you doalias sh="PS1'$0\$ ' sh"
- you're quoting the hardquotes - and$0
is expanded. But this would work:alias sh="PS1='\$0\$ ' sh"
. – mikeserv Jul 30 '14 at 12:12$0
atalias
definition time. Sorry about that. Anyway, the command still works, I just got ahead of myself I guess. And by the way, this makes for a pretty handy prompt insh
mode. – mikeserv Jul 30 '14 at 12:23sh
is being read when you you call a subshell inbash
? I mean, the subshell has a defaultPS1
of$
, where does that come from? Where is that default defined? – Stefan van den Akker Jul 30 '14 at 13:14sh
is just a link tobash
run likebash --posix --norc --noprofile
. At least I think that makes all of it. You're not actually running a program all its own. – mikeserv Jul 30 '14 at 17:19