I’m using the following bash Test for one condition and it’s working correctly
[[ $# == 1 ]] || { echo "Syntax: $0 arg1"; exit 1; }
But when I try to use 2 conditions like the following:
[[ $#==1 || $#==2]] || { echo "Syntax: $0 old_json_file_configuration [new_json_config_destination]"; exit 1; }
… or from stackoverflow something like this:
[[ $#==1 -o $#==2]] || { echo "Syntax: $0 old_json_file_configuration [new_json_config_destination]"; exit 1; }
I receive: conditional binary operator expected. I was looking also here in LinuxExchange and I saw several options using if, that I can use however I would like to know what would be missing with my line.
6
The spaces aren’t optional.
[[ $#==1 || $#==2]] # Wrong.
[[ $# == 1 || $# == 2 ]] # Right.
# ~ ~ ~ ~ ~ # The spaces.
In fact, the spaces around ||
are, but it’s better to keep the code readable.