Override a variable in a Bash script from the command line

前端 未结 4 592
悲&欢浪女
悲&欢浪女 2020-12-13 00:19

How do you override a variable in your Bash script from the command line?

I know how to pass variables in, but I just want something like ./myscript.sh -Dvar=v

4条回答
  •  生来不讨喜
    2020-12-13 01:06

    I would do it like this:

    # if JAVA_HOME not set, then set with default value
    if [ "x$JAVA_HOME" = "x" ]; then
        JAVA_HOME=/opt/java
    fi
    

提交回复
热议问题