2

I run following series of commands to bring curser under the prompt on shell terminal.

$ NL='              # << press enter
'                   # << press enter again
$ PS1=${PS1}${NL}

I've to do this every time I login. How can I automate it? I tried add these same statements in ~/.profile and restarted. No luck.

EDIT:

Here's how I did it. I added following (my favorite bash prompt) line in ~/.bashrc (I created it).

export PS1="===================\n\n\d \A \u@\H [\w]\n\\$ \[$(tput sgr0)\]"

5

Use NL=$'\n'. You also need to double-quote $NL when you use it (and probably $PS1 too, depending on what it contains...include it inside the double-quotes anyway).

e.g. add to your ~/.bash_profile (or ~/.profile if you prefer):

NL=$'\n'
PS1="${PS1}${NL}"

BTW, in the long run, I'll bet you get sick of how much valuable vertical terminal space is wasted by the extra newline. Screens tend to be much wider than they are tall (e.g. some common resolutions for a 16:9 aspect ratio are 1920x1080 or 2560x1440, while common resolutions for 16:10 are 1920x1200 or 2560x1600), so vertical screen space is rarer and more valuable. The more wasted space, the less useful info you can see on screen at once.

  • 1
    "Screens tend to be much wider than they are tall" Here I beg to differ - not everyone uses 16:9, or the whole screen for a terminal window. A newline in the prompt IMHO makes sense when you have a window with 80 columns and 50+ lines. – Murphy Apr 11 '16 at 11:27
  • 1
    Whether you use an <= 80-column terminal or a more sensible 132+ columns, what i said is still true - screens are wider than they are tall. even old-fashioned screens used a 4:3 aspect ratio. BTW, my terminal is currently 192x51 lines and I'd still never waste valuable vertical screen space by printing unnecessary newlines in every prompt...i wouldn't do it even if my terminal was 100 or more lines high. – cas Apr 11 '16 at 11:35
  • Allright, you optimize for space, I tend to optimize for readability. Compare the answers to a recent question for additional opinions. – Murphy Apr 11 '16 at 11:41
  • I optimise for both space and readability. In a terminal, excess newlines detract from readability by requiring me to use the scrollbar/scroll-keys more often. – cas Apr 11 '16 at 11:43
  • 4
    There are many ways that screens can be taller than wide. FBCon rotation for one; xterms on a graphical system for another. Let's not judge how others want to work (just be grateful we're not all obliged to follow One True Way like certain OSes' users...) – Toby Speight Apr 11 '16 at 14:25
3

You might want to be explicit about the contents of your prompt:

PS1='\u@\h:\w\n\$ '

See https://www.gnu.org/software/bash/manual/bashref.html#Controlling-the-Prompt

And I have a three line prompt which works very well for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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