Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 01-04-2004, 04:46 PM   #1
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

/etc/bootsplash/ <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:

POS=`expr $POS + 1`
/etc/bootsplash/ $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.
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 01-04-2004, 05:25 PM   #2
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
Senior Member
Registered: Oct 2003
Posts: 3,057

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

Rep: Reputation: 22

: you can even leave the $ off the y.


: 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
LQ Guru
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
bash-3.1$ x=5
bash-3.1$ let x++
bash-3.1$ echo $x
2 members found this post helpful.
Old 02-21-2009, 12:25 PM   #6
Registered: Jun 2008
Location: Dallas, TX
Distribution: Slackware and FC
Posts: 113

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

$: x=1

$: ((x++))

$: echo $x
1 members found this post helpful.


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

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 > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:01 PM.

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