Learning Old School Linux

Home > Other > Learning Old School Linux > Page 11
Learning Old School Linux Page 11

by Ed Hartnett

It's important that you don't put spaces around your equal sign (=) when using export. There must be no spaces between the variable you are setting, the equal sign, and the value you are setting it to. Also note the use of the single-quote character around the string value. Without those quotes, the shell would get confused by the spaces in the string, and would set PS1 to "what," and then try to process the rest of the string as additional arguments to export.

  There are three quotes on your keyboard: the single quote, the back-tick (a single quote facing the other way), and the double quote. On a U.S. keyboard, the single quote and double-quote are on the same key, near the Enter key. The back-tick is on the upper-left, with the tilde. Each of these sets of quotes means something different, so make sure you are using the correct one.

  To play around with prompts, you can set them from the command line, but to change your default prompt, you are going to have to set the PS1 variable in your .bashrc file.

  By setting PS1, you can have any string as your prompt. But there is so much more!

  Built-In Fields

  The bash shell has a bunch of built-in fields for the prompt—special character strings that you can put into PS1 to change the look of the prompt. For example, if you want the time in your prompt, use 'D{}' in PS1.

  what is your command human? export PS1="D{}> "

  07:54:11 AM>

 

‹ Prev