Bash – Execute Random Command

bashrandom

I want my bash script to execute random command of given below.
For example

[mysterious command] ("command1", "command2", "command3")

Best Answer

This should accomplish what you're looking for.

COMMANDS=("command1" "command2" "command3")
$(shuf -n1 -e "${COMMANDS[@]}")

Takes the array and uses shuf to generate a random command.

UPDATE: Changed shuf command per @steeldriver

Related Question