LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   SHELL SCRIPT Write at the right of the shell window (https://www.linuxquestions.org/questions/linux-general-1/shell-script-write-at-the-right-of-the-shell-window-758408/)

solo9300 09-29-2009 03:50 AM

SHELL SCRIPT Write at the right of the shell window
 
Hello all,

Is there an easy way to write at the right of a shell window in shell script ? For example:

My service [at the left]: OK [at the right]

Any help would be much appreciated.

slakmagik 09-29-2009 04:17 AM

Probably an easy obvious way but all that springs to mind is:
Code:

string="My service:"
printf "%s%$((${COLUMNS}-${#string}))s" "$string" "OK"

-- Oh, come to think of it, I'm not sure if you count on COLUMNS being available. If not,

Code:

printf "%s%$(($(stty size | cut -d' ' -f2)-${#string}))s" "$string" "OK"
should do the same.

lumak 09-29-2009 10:53 AM

Thank you slakmagik! I wanted to use the number of rows in a script once but $LINES isn't available inside scripts. Much help indeed.

That fixes that.
Code:

#!/bin/env /bin/sh
TTY_LINES=$(stty size | cut -d' ' -f1)
let " LINES = TTY_LINES - 4"
watch "dmesg | tail --lines=$LINES"


slakmagik 09-29-2009 04:56 PM

Glad it helped you both. :)


All times are GMT -5. The time now is 11:00 AM.