LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 01-04-2004, 04:46 PM   #1
andrewb758
Member
 
Registered: Jan 2003
Location: Columbus, OH USA
Distribution: Debian unstable
Posts: 63

Rep: Reputation: 15
bash equivalent to C increment operator


I am modifying my init scripts to run a bootsplash progress bar. A seperate script is called to advance the bar, and it works like this

Code:
/etc/bootsplash/progress.sh <position> <num actions> ...
there are other options for fbtruetype but they are not relevant here. The script then uses expr to find out 65535 * pos / actions. That is the location of the bar (echo "show x" > /proc/splash). In order to make adding positions easy, in the init script, the total number of actions is defined in an variable at the top (NUM_ACTIONS). POS is defined as 0, and this is used to move the bar along:

Code:
NUM_ACTIONS=...
POS=0
...
POS=`expr $POS + 1`
/etc/bootsplash/progress.sh $POS $NUM_ACTIONS ...
My question is, is there an increment operator in bash that will display the increased variable and increase its value in memory in one action, similar to that in C? Thanks in advance.
 
Old 01-04-2004, 05:25 PM   #2
TheOther1
Member
 
Registered: Feb 2003
Location: Atlanta, GA
Distribution: RHAS 2.1, RHEL3, RHEL4, SLES 8.3, SLES 9, SLES9_64, SuSE 9.3 Pro, Ubuntu, Gentoo
Posts: 335

Rep: Reputation: 32
From Advanced Bash Scripting Guide:

y=`expr $y + 1`
Increment a variable, with the same effect as let y=y+1 and y=$(($y+1)) .
 
Old 01-04-2004, 06:13 PM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
I wonder if this would be of any use to you......
_________________________________________
#!/bin/bash
#
echo ""
echo -n "Num_Actions: "
read NUM
for ((POS=1; POS <=$NUM ; POS++)); do
echo
done
#
/etc/bootsplash/progress.sh $POS $NUM_ACTIONS
#
#End
 
Old 02-19-2009, 11:59 PM   #4
stoggy
Member
 
Registered: Jun 2008
Location: Dallas, TX
Distribution: Slackware and FC
Posts: 104

Rep: Reputation: 20
y=$[$y+1]

: you can even leave the $ off the y.

y=$[y+1]

: but to me it looks confusing.


a little faster, of course so is c, c++, perl, and python. probably even java.

I like bash too. Yea! only 5 years late too! Maybe someone will find this useful.

Last edited by stoggy; 02-20-2009 at 12:02 AM.
 
Old 02-20-2009, 01:39 AM   #5
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266Reputation: 1266
Code:
bash-3.1$ x=5
bash-3.1$ let x++
bash-3.1$ echo $x
6
 
Old 02-21-2009, 12:25 PM   #6
stoggy
Member
 
Registered: Jun 2008
Location: Dallas, TX
Distribution: Slackware and FC
Posts: 104

Rep: Reputation: 20
you could also use "((" and "))"

$: x=1

$: ((x++))

$: echo $x
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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
increment in hex snutz411 Linux - Newbie 2 11-01-2005 05:54 PM
Bash scripting and && operator Dark_Helmet Programming 16 09-18-2005 09:57 PM
bash equivalent to tcsh's \!* tdp05 Programming 1 09-03-2004 04:08 AM
bash script and the , operator xviddivxoggmp3 Programming 1 08-14-2004 12:33 AM
facing problem in increment operator of set :infinite LOOP ashwinipahuja Programming 0 06-03-2004 12:05 AM


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