Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am wondering why the following script won't work:

read -p 'First lets write PROMPT.SH'
echo '#!/bin/bash'>
echo "export PS1='\e[1;31m\]\u@\h \W\$\e[0m\] '">>
read -p "Change Title and Prompt"
echo texttexttext
read -p "Now lets tidy up PROMPT.SH"
rm ./
read -p "That was the program"

What I am trying to do is change the window title, prompt, and text color that I can normally do with,

PS1='\e[1;31m\]\u@\h \W\$\e[0m\] '

during a regular bash session but not when I add it to a script and then run the script.

share|improve this question

PS1 is only displayed for interactive prompts. It has nothing to do with the prompt shown for read -p. Execution of a bash script, even if reading input, is not considered interactive.

share|improve this answer

I’m not crystal clear on what you’re trying to do, but I guess it’s setting PS1 for your interactive shell from a script.  Stated like that, you cannot do it.  In *nix and Unix-like systems, process characteristics/ properties get passed from parent to child, but never the other way around.  For example, if you set your PATH to include /foo, and then you run a script that tries to run bar, it will find /foo/bar — but if you change PATH in a script, it doesn’t affect your interactive shell.  Likewise for cd and umask. These are differences from the Windows Command Prompt (batch) world.

That said, there is an answer, and you already know it.  If your script (the 10-line one) is called, then you should be able to get the effect you want by typing source  But that’s silly overkill (unless you’re doing it just for script-writing practice); just put

PS1='\e[1;31m\]\u@\h \W\$\e[0m\] '

into and type source

But also research the alias command.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.