I have created a bash script which will extract a
tar.gz file which is decompressed 5 times and remain the last
tar.gz file decompressed. When I execute this acript I got this error
line 26: 0++: syntax error: operand expected (error token is "+") . Please see below script.
for tarfile in *.tar.gz
[ $i = 5 ] && break
tar -xf "$tarfile"
What is the error about and what is the correct way to solve my problem which is extracting the file five times and remain the last file decompressed. Thanks in advance for those who help.
Best How To :
you want to change
((i++)). see http://askubuntu.com/questions/385528/how-to-increment-a-variable-in-bash
$(($i++)). going outwards,
$i expands to 0. so we have the expression
$((0++)). 0 can't be incremented since it is a value, not a variable. so you get your error message
line 26: 0++: syntax error: operand expected (error token is "+").
The reason to use
((i++)) without a $ at the front is that the $ at the front would actually evaluate
i. You don't want
i to be evaluated here, you just want
i to be incremented. (h/t the other guy)