LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 07-07-2005, 12:35 AM   #1
gravesb
Member
 
Registered: May 2005
Distribution: Suse 9.3, Gentoo
Posts: 87

Rep: Reputation: 15
issues programming a script in BASH


I am working through a book about scripting in UNIX, and I cannot get the follwing script to work correctly.

#center_text row_number input_text_file
max_cols='tput cols'
max_lines='tput lines'
row_number=$1
shift
cat $* | \
while read input_text
do
line_length='echo $input_text | wc -c'
tput cup $row_number \ 'expr \( $term_cols - $line_length \) / 2'
echo $input_text
row_number='expr $row_number + 1'
if [ $row_number -ge $max_lines ]
then
echo "Too many lines for the screen"
break
fi
done



The issue is that the -ge statement is getting two many inputs because the $row_number variable is evaluating to expr $row_number + 1 as a string instead of a number. I tried using (()) notation and using the ` instead of the ', as well as a host of other solutions, but none seem to work. I am sure that the solution is simple, and I am an idiot, but if anyone can post what I am doing incorrectly, I would greatly appreciate it. Thanks
 
Old 07-07-2005, 01:03 AM   #2
65_289
Member
 
Registered: May 2002
Distribution: Ubuntu 5.04, Kanotix
Posts: 163

Rep: Reputation: 30
This works for me:

#!/bin/bash
num1=1
echo $num1
num1=$(($num1+1))
echo $num1


Output:
1
2
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Programming moodupani Programming 1 08-31-2005 06:50 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
Bash script programming questions dianea Linux - Newbie 4 03-03-2004 12:17 AM
bash programming bulliver Programming 2 04-05-2003 09:30 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM


All times are GMT -5. The time now is 06:03 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