gpt4 book ai didi

linux - 如何在 Linux 中更新环境变量?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:44:27 24 4
gpt4 key购买 nike

我定义了一个环境变量:export NBR_PROCESS=2

基本上,我应该能够更新变量,但是当我执行以下脚本时,每次运行都会得到相同的结果:

#!/bin/bash
echo "Script 2: Before decrement : $NBR_PROCESS"
export NBR_PROCESS=$(($NBR_PROCESS - 1))
echo "Script 2: After decrement : $NBR_PROCESS"

每次执行我都会得到以下相同的结果:

Script 2: Before decrement : 2
Script 2: After decrement : 1

我想做的是通过运行脚本来减少变量 NBR_PROCESS

最佳答案

你必须“来源”

来源 your_script


编辑1
参见 this answer...


编辑 2

。文件名[参数]或者源文件名[参数]

Complete explanations:

Read and execute commands from the filename argument in the current shell context. If filename does not contain a slash, the PATH variable is used to find filename. When Bash is not in POSIX mode, the current directory is searched if filename is not found in $PATH. If any arguments are supplied, they become the positional parameters when filename is executed. Otherwise the positional parameters are unchanged. The return status is the exit status of the last command executed, or zero if no commands are executed. If filename is not found, or cannot be read, the return status is non-zero. This builtin is equivalent to source.

关于linux - 如何在 Linux 中更新环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12145753/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com