Is there some way to assign one value out of some possible values in shell like this :
variable = $(command1) or $(command2)
Knowing that only one of these two commands gives a result
The || operator will evaluate command2 if command1 returns a non-zero (error) return code.
variable=$(command1 || command2)
Similarly, the && operator will evaluate command2 if command1 returns a (ok) zero return code.
variable=$(command1 && command2)
e.g. Assignment of variable:
var=$(ls zasdasd || echo "file does not exist")
echo $var ## outputs "file does not exist"
Error output can be suppressed by directing error stream 2 to /dev/null
var=$(ls zasdasd || echo "file does not exist") 2>/dev/null