0

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

2 Answers 2

5

The $ is only needed when reading the current value.

export PS1="test"
1
  • 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, 2010 at 13:22
3

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .