tags:

views:

38

answers:

2

In bash, some commands put their stdout BEFORE the command prompt and on the SAME line. For example:

$ printf message
message$ 
$ gettext -d gtk20 File
Fichier$ 

I want the stdout on a dedicated line with the command prompt on the NEXT line. I could precede with 'echo' and wrap in back ticks like this, but I wonder if there is a better way (an arg that can be always/often used, etc):

$ echo `printf message`
message
$
$ echo `gettext -d gtk20 File`
Fichier
$ 
+1  A: 

Try adding a ; printf "\n" or ; echo after your command. The issue is that your output does not end with a newline.

You could also just inject the command output into a single printf "%s\n" command.

Borealid
A: 

You can set your prompt to handle this for you automatically.

PS1='$(printf "%$(($(tput cols)-1))s\r")\u@\h [\w]\$ '

From this question on Server Fault.

It prints enough spaces to wrap around the end of the line then a carriage return (\r) to return to the first column. You can customize what it displays after that the same way you normally would.

Dennis Williamson