Как объединить эти три команды поиска в одну?

Переменная среды

When a program is invoked it is given an array of strings called the environment. This is a list of name-value pairs, of the form name=value.

Bash provides several ways to manipulate the environment. On invocation, the shell scans its own environment and creates a parameter for each name found, automatically marking it for export to child processes. Executed commands inherit the environment. The export and ‘declare -x’ commands allow parameters and functions to be added to and deleted from the environment. If the value of a parameter in the environment is modified, the new value becomes part of the environment, replacing the old. The environment inherited by any executed command consists of the shell’s initial environment, whose values may be modified in the shell, less any pairs removed by the unset and ‘export -n’ commands, plus any additions via the export and ‘declare -x’ commands.

Эти переменные будут видны всем сценариям, выполняемым в этой среде

Вы можете просмотреть их, выполнив команду env.

Они устанавливаются либо с помощью встроенной функции export, либо с помощьюdeclare -x


Глобальная переменная

Глобальная переменная будет видна всем внутри одной программы (скрипта ), включая дочерние процессы, созданные подоболочками/функциями, но не между программами (скриптами ).

Любая переменная, не экспортированная специально и не объявленная как локальная, будет глобальной переменной.


Локальная переменная

Variables local to the function may be declared with the local builtin. These variables are visible only to the function and the commands it invokes. This is particularly important when a shell function calls other functions.

Local variables "shadow" variables with the same name declared at previous scopes. For instance, a local variable declared in a function hides a global variable of the same name: references and assignments refer to the local variable, leaving the global variable unmodified. When the function returns, the global variable is once again visible.

The shell uses dynamic scoping to control a variable’s visibility within functions. With dynamic scoping, visible variables and their values are a result of the sequence of function calls that caused execution to reach the current function. The value of a variable that a function sees depends on its value within its caller, if any, whether that caller is the "global" scope or another shell function. This is also the value that a local variable declaration "shadows", and the value that is restored when the function returns.

For example, if a variable var is declared as local in function func1, and func1 calls another function func2, references to var made from within func2 will resolve to the local variable var from func1, shadowing any global variable named var.

Эти переменные будут видны только функции, в которой они объявлены, и любым дочерним функциям.

Эти переменные должны быть специально объявлены как локальные с помощью встроенной функции localили просто с помощью declareвнутри функции.

0
19.08.2021, 03:32
0 ответов

Теги

Похожие вопросы