是否可以使用短路为shell脚本设置变量默认值?
脚本调用1: my_script.sh "apple" "carrot"
脚本调用2: my_script.sh "apple"
my_script.sh:
#!/bin/bash
fruit=$1
vegetable=$2 || "green bean"
# Do something with fruits and vegetables
Run Code Online (Sandbox Code Playgroud)
当我这样做时,似乎没有使用默认值.