But the following shows that
when "return" is used the replacement can not be done.
It can be done. See below
Is there a way
to use "&&" to replace "if" even "return" or "exit" is used?
It is. You used it. But you don't understand return statuses. See below.
~/linux/test/bash/man/operator/&&/return$ cat.sh *
==> main.sh <==
#!/usr/bin/env bash
set -v
function cmd1 {
[ '' ] && return 1
}
cmd1
echo $?
function cmd2 {
[ x ] && return 1
}
cmd2
echo $?
function cmd1 {
if [ '' ]
then
return 1
fi
}
cmd1
echo $?
function cmd2 {
if [ x ]
then
return 1
fi
}
cmd2
echo $?
==> main_echo.sh <==
#!/usr/bin/env bash
set -v
function cmd1 {
[ '' ] && echo 1
}
cmd1
function cmd2 {
[ x ] && echo 1
}
cmd2
function cmd1 {
if [ '' ]
then
echo 1
fi
}
cmd1
function cmd2 {
if [ x ]
then
echo 1
fi
}
cmd2