本文介绍了内联变量赋值和 Bash 中的常规变量赋值有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么区别:

prompt$   TSAN_OPTIONS="suppressions=/somewhere/file" ./myprogram

prompt$   TSAN_OPTIONS="suppressions=/somewhere/file"
prompt$   ./myprogram

thread-sanitizer 库提供了第一个案例,说明如何让他们的库(在 myprogram 中使用)来读取选项中给出的文件.我读了它,并假设它应该是两个单独的行,所以将它作为第二种情况运行.

The thread-sanitizer library gives the first case as how to get their library (used within myprogram) to read the file given in options. I read it, and assumed it was supposed to be two separate lines, so ran it as the second case.

库在第二种情况下不使用该文件,其中环境变量和程序执行在不同的行上.

The library doesn't use the file in the second case, where the environment variable and the program execution are on separate lines.

有什么区别?

额外问题:第一个案例如何运行而没有错误?不应该有一个;或&&它们之间?这个问题的答案可能会回答我的第一个问题......

Bonus question: How does the first case even run without error? Shouldn't there have to be a ; or && between them? The answer to this question likely answers my first...

推荐答案

VAR=value 命令的格式设置变量VAR的值为value 在命令 command 的环境中.涵盖此内容的规范部分是 简单命令.具体来说:

The format VAR=value command sets the variable VAR to have the value value in the environment of the command command. The spec section covering this is the Simple Commands. Specifically:

否则,变量分配应为命令的执行环境导出,并且不应影响当前执行环境,除非是在步骤 4 中执行的扩展的副作用.

格式VAR=value;command当前shell 中设置shell 变量VAR,然后将command 作为子进程运行.子进程对shell进程中设置的变量一无所知.

The format VAR=value; command sets the shell variable VAR in the current shell and then runs command as a child process. The child process doesn't know anything about the variables set in the shell process.

进程导出(提示提示)变量以供子进程查看的机制是在运行子进程之前将它们设置在其环境中.执行此操作的内置 shell 是 export.这就是为什么你经常看到 export VAR=valueVAR=value;导出 VAR.

The mechanism by which a process exports (hint hint) a variable to be seen by child processes is by setting them in its environment before running the child process. The shell built-in which does this is export. This is why you often see export VAR=value and VAR=value; export VAR.

您正在讨论的语法是类似于以下内容的缩写形式:

The syntax you are discussing is a short-form for something akin to:

VAR=value
export VAR
command
unset -v VAR

完全不使用当前进程环境.

only without using the current process environment at all.

这篇关于内联变量赋值和 Bash 中的常规变量赋值有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 10:20