Is it possible to set variable defaults for a shell script using short circuiting?
Script call 1: my_script.sh "apple" "carrot"
Script call 2: my_script.sh "apple"
my_script.sh:
#!/bin/bash
fruit=$1
vegetable=$2 || "green bean"
# Do something with fruits and vegetables
When I do that, it doesn’t seem like the default ever gets used.
Did you indicate that the script should use a specific shell? I always defaul to usebashas so:Nice explanation of the concept here.
EDIT: Okay, I better understand the question now. The original poster wants to set default values if variables are not passed. Nice explanation on setting default variables here. Try this script: