LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash equivalent to C increment operator (https://www.linuxquestions.org/questions/linux-general-1/bash-equivalent-to-c-increment-operator-131504/)

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

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.

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......
_________________________________________
#!/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

stoggy 02-19-2009 11:59 PM

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.

H_TeXMeX_H 02-20-2009 01:39 AM

Code:

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


stoggy 02-21-2009 12:25 PM

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

$: x=1

$: ((x++))

$: echo $x
2


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