-   Linux - General (
-   -   bash equivalent to C increment operator (

andrewb758 01-04-2004 04:46 PM

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.

TheOther1 01-04-2004 05:25 PM

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)) .

homey 01-04-2004 06:13 PM

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

stoggy 02-19-2009 11:59 PM


: 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.

H_TeXMeX_H 02-20-2009 01:39 AM


bash-3.1$ x=5
bash-3.1$ let x++
bash-3.1$ echo $x

stoggy 02-21-2009 12:25 PM

you could also use "((" and "))"

$: x=1

$: ((x++))

$: echo $x

All times are GMT -5. The time now is 08:53 AM.