x=3 x++ print $x
x=3 x=x+1 print $x
#!/bin/bash
count=0
count=`expr ${count} + 1`
Here’s an example. Suppose you want to use the rpm command to install/remove something, but you don’t know if it’s running already? You can make a timer that increments and go into a deeper and deeper sleep the longer you’re waiting for rpm to go away from the process list.
#!/bin/bash
inception=1
while [ "`pgrep rpm | wc -l`" != 0 ]; do
sleep ${inception}
inception=`expr ${inception} + 1`
echo "Sleeping ${inception} seconds..."
done
rpm -Uvh awesome-1.0.x86_64.rpm
11:48 am
You can also use arithmetic expansion:
inception=0
…
sleep $((inception += 1))
see http://tldp.org/LDP/abs/html/arithexp.html