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
.bashrcnamed.shrc - I put only one line in it:
export PS1='$(echo ${0})\$ ' I then modified
~/.profileto 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 fiI restarted the terminal, but the changes are not being applied.
- If I run
. ~/.shrcinshmanually, 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$PS1is special - it isevaled 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$0yet - that's stillbashat that time. If you doalias sh="PS1'$0\$ ' sh"- you're quoting the hardquotes - and$0is expanded. But this would work:alias sh="PS1='\$0\$ ' sh". – mikeserv Jul 30 '14 at 12:12$0ataliasdefinition 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 inshmode. – mikeserv Jul 30 '14 at 12:23shis being read when you you call a subshell inbash? I mean, the subshell has a defaultPS1of$, where does that come from? Where is that default defined? – Stefan van den Akker Jul 30 '14 at 13:14shis just a link tobashrun 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