You already have all the building blocks you need, you just need to reverse the logic (and fix a small syntax error).
First off, a bit of background.
[ is (basically) an alias to
test. Much of this can be found (in bits and pieces) in the test(1) man page; even though learning the syntax for everything is probably not practical particularly to begin with, I recommend familiarising yourself with what
test is capable of doing.
If I understand your question correctly, you want to execute the
rar command if and only if
$NOMBREX2 is not equal to "0".
test has a lot of conditional operators, including
= ("the strings are equal") and
!= ("the strings are not equal"). Note that integer values use different operators including
-ne respectively. Why it's done that way is beyond me, but that's water under the bridge by now.
There are two ways in bash to run a command if a statement evaluates to true, or more accurately if a command returns a zero exit status; either enclose it in an
if ...; then .. fi block, or use the
&& operator to separate the commands. You can do the same thing if you want to execute a command when a statement evaluates to false (returns a non-zero exit status);
if ! ...; then ... fi (the
! means "not") or use
|| between the commands.
Since we already know that the condition you want for executing the
rar command is an inequality comparison, we can write that in two different ways (assuming you want string comparisons; otherwise, instead of
-ne in the conditions):
Option 1 (idiomatic, good for simple conditions and single commands):
test "$NOMBREX2" != "0" && rar a -r ...
Option 2 (good for more complex conditions or multiple commands):
if [ "$NOMBREX2" != "0" ]; then
rar a -r ...
# ... anything else goes here ...