简体   繁体   English

如何在bash中从另一个脚本初始化变量?

[英]How to initialize a variable from another script in bash?

How can I set my intial variables in a re-usable way? 如何以可重复使用的方式设置我的初始变量? I tried to do this by invoking something like this in my child script: 我尝试通过在我的子脚本中调用类似的东西来做到这一点:

 ./init.bash

And inside init.bash: 在init.bash里面:

prod="false"

if [ "$prod" == "prod" ]
then
    RUN_DIR=/home/windsor/.scripts/websites
    JAVA_DIR=/home/windsor/prog/websitechecker
    OUT_DIR=/tmp/
    DB="prod"
else
    if [ ! -a /tmp/test ]
    then
        mkdir /tmp/test
    fi
    DB="mydb"
    OUT_DIR=/tmp/test/
    RUN_DIR=/home/windsor/workspaces/bash/websites
    JAVA_DIR=/home/windsor/workspaces/java/testrun
fi

cd $RUN_DIR

Use the source command: 使用source命令:

source ./init.bash

If you are typing it in on the command-line, you can use the shortcut: 如果在命令行中输入,则可以使用快捷方式:

. ./init.bash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM