开发者

bash stdout followed by prompt on same line

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 `gette开发者_JAVA百科xt -d gtk20 File`
Fichier
$ 


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜