When I run a curl command, the json response that it returns collides with the bash prompt string:

~$curl localhost:8001/api
{"message":"this is a test message"}~$

Notice ~$ at the end of second line. I have customized my bash prompt string to contain the working folder:

PS1=\[\e]0;\u@\h: \w\a\]\W\$

It appears the local server (nodejs) hasn't added a newline character at the end.

How can I ensure that my bash prompt string always comes at a newline?

  • Why dont you just add echo ""after curl: curl localhost:8001/api;echo "" – 7171u Jul 22 '15 at 12:11
  1. Simple answer: use the \n (newline) special character at the beginning of your prompt string. It will ensure the bash prompt string always comes at a newline. This might however happen more often than you'd want.
  2. If you only run into this when using curl, have a look at this answer

If you only want to do this for curl commands and don't want an extra newline added to your prompt, just echo the output:

~$ echo "$(curl localhost:8001/api)"
{"message":"this is a test message"}

You can force a newline after every command in the bash shell with the PROMPT_COMMAND.


Now, after every command or before every prompt echo is called without argument. Then echo only prints a newline. Notice, that if you run a command that ends with a newline, you will now have 2 newlines at the end. See:

echo -n foo
echo -n foo
$ echo foo


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.