Padding characters in printf

前端 未结 13 779
半阙折子戏
半阙折子戏 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条回答
  • 2020-11-30 17:57

    Here's another one:

    $ { echo JBoss DOWN; echo GlassFish UP; } | while read PROC STATUS; do echo -n "$PROC "; printf "%$((48-${#PROC}))s " | tr ' ' -; echo " [$STATUS]"; done
    JBoss -------------------------------------------- [DOWN]
    GlassFish ---------------------------------------- [UP]
    
    0 讨论(0)
提交回复
热议问题