Padding characters in printf

前端 未结 13 841
半阙折子戏
半阙折子戏 2020-11-30 16:58

I am writing a bash shell script to display if a process is running or not.

So far, I got this:

printf \"%-50s %s\\n\" $PROC_NAME [UP]
13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 17:49

    There's no way to pad with anything but spaces using printf. You can use sed:

    printf "%-50s@%s\n" $PROC_NAME [UP] | sed -e 's/ /-/g' -e 's/@/ /' -e 's/-/ /'
    

提交回复
热议问题