I'm on Mac OSX and trying to test out some new prompt settings in terminal. Here's my setup

$ echo $PS1
$ \h:\W \u\$

This prompt works fine. But if I type

$ export $PS1="test"

I get the following errors

-bash: export: `\h:\W': not a valid identifier
-bash: export: `\u\$': not a valid identifier
-bash: export: `=test': not a valid identifier

Any ideas on why this is happening? I don't have a .bashrc file but I do have an /etc/bashrc file

link|improve this question
feedback

2 Answers

up vote 5 down vote accepted

The $ is only needed when reading the current value.

export PS1="test"
link|improve this answer
Yes. You need the $ in a variable to read its value. Example: $PS1. But you do not use a $ when setting its value. Example: PS1. – Wuffers Oct 10 '10 at 13:22
feedback

Your export command expanded the prompt variable and tried to export the string "\h:\W \u\". You got an error message because those three substrings don't exist as variable names. As Ignacio Vazquez-Abrams indicated, you need to drop the leading "$" in the export command, which will then export the PROMPT variable as you intended. Brief version: By specifying the PROMPT to be expanded, the command tried to export the wrong thing.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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