LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 09-29-2009, 03:50 AM   #1
solo9300
LQ Newbie
 
Registered: Sep 2009
Posts: 13

Rep: Reputation: 0
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.
 
Old 09-29-2009, 04:17 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
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.

Last edited by slakmagik; 09-29-2009 at 04:21 AM.
 
Old 09-29-2009, 10:53 AM   #3
lumak
Member
 
Registered: Aug 2008
Location: Phoenix
Distribution: Arch
Posts: 799
Blog Entries: 32

Rep: Reputation: 109Reputation: 109
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"

Last edited by lumak; 09-29-2009 at 10:58 AM.
 
Old 09-29-2009, 04:56 PM   #4
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Glad it helped you both.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 06:24 AM
Need help to write shell script vikrambhimbar Linux - Software 1 09-22-2006 05:25 AM
help to write shell script vikrambhimbar Linux - Software 2 04-03-2006 04:43 AM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 03:00 PM


All times are GMT -5. The time now is 05:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration