I would like to increment a variable if an execution failed.
I tested the logic by using a script like:
#!/bin/bash
if [ ! -f "/tmp/init" ]
then
var=0
echo $var
export var
touch /tmp/init
fi
if [ "$1" -eq 1 ]
then
(( var++ ))
export var
fi
echo $var
I obtain the result:
:~# ./script.sh 1
0
1
:~# ./script.sh 1
2
:~# ./script.sh 1
2
Is there an easy way to do this stuff?
echo $var > /tmp/initafter yourvar++line. $var disappears when you come out of your script.exportmakes it available to its children, not to its parent.