Using a script, I was to change the prompt of the parent Bash shell. I have tried the following:
PS1="Hello World > "
This changes the prompt of the subshell, which the script is running in, but which command would I use to change the prompt of the parent shell. Any ideas?
In all cases the parent shell must cooperate. The child process in a unix environment cannot influence the parent process without its cooperation.
Try this in the subshell script changePrompt.sh
:
echo 'PS1="Hello World > "'
And then call the script from the parent shell like this:
eval "$(changePrompt.sh)"
Or, a different approach: Source the script instead of calling it. changePrompt.sh
:
PS1="Hello World > "
Call it like this:
source changePrompt.sh
or simply:
. changePrompt.sh
you have to edit the .bash_rc file, with what you want... just straight up add PS1="blah" or whatever.
the .bash_rc file should be in your home dir /user/home or whatever (its hidden so "ls -la")
when you have edited it, source it, and it should work (source .bash_rc) -- assuming same dir
if that doesnt work try the .rc file.... this is system wide though for all shells (or at least it should be)..... try here for more info:
http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html --- here
来源:https://stackoverflow.com/questions/9991116/changing-ps1-prompt-in-a-bash-parent-shell