Skip to main content
added 122 characters in body
Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

This doesn't do exactlyAssuming that what you want, as it doesn't actually create to do is to give a newprocess an environment variable with a value that may be different from the value of the shell variable with the same name that may be in scope in the current shell at the point of invocation of the command:

a () {
    YACY_TIMEOUT=60 yacy -r -d std
}

This is the standard syntax for running a command and giving it a particular value of an environment variable. The variable YACY_TIMEOUT, if it exists in the same scope as the body of the a function, would not be modified.

This would work in any POSIX shell.

What this does not do is to allow you to use YACY_TIMEOUT with the "local" value inside the function before calling yacy.

In zsh or any other shell that supports local variables declared with local, you could do

a () {
    local YACY_TIMEOUT=60

    YACY_TIMEOUT=$YACY_TIMEOUT yacy -r -d sth
}

Here, YACY_TIMEOUT would be local to the a function. The injection of the variable as an environment variable in the yacy process happens as in the first example I gave, by preceding the invocation by an assignment.

Now YACY_TIMEOUT is both local and is also available in the yacy process' environment. This would work in any shell that supports using local to declare local variables.

This doesn't do exactly what you want, as it doesn't actually create a new variable in the current shell:

a () {
    YACY_TIMEOUT=60 yacy -r -d std
}

This is the standard syntax for running a command and giving it a particular value of an environment variable. The variable YACY_TIMEOUT, if it exists in the same scope as the body of the a function, would not be modified.

This would work in any POSIX shell.

What this does not do is to allow you to use YACY_TIMEOUT with the "local" value inside the function before calling yacy.

In zsh or any other shell that supports local variables declared with local, you could do

a () {
    local YACY_TIMEOUT=60

    YACY_TIMEOUT=$YACY_TIMEOUT yacy -r -d sth
}

Here, YACY_TIMEOUT would be local to the a function. The injection of the variable as an environment variable in the yacy process happens as in the first example I gave, by preceding the invocation by an assignment.

Now YACY_TIMEOUT is both local and is also available in the yacy process' environment. This would work in any shell that supports using local to declare local variables.

Assuming that what you want to do is to give a process an environment variable with a value that may be different from the value of the shell variable with the same name that may be in scope in the shell at the point of invocation of the command:

a () {
    YACY_TIMEOUT=60 yacy -r -d std
}

This is the standard syntax for running a command and giving it a particular value of an environment variable. The variable YACY_TIMEOUT, if it exists in the same scope as the body of the a function, would not be modified.

This would work in any POSIX shell.

What this does not do is to allow you to use YACY_TIMEOUT with the "local" value inside the function before calling yacy.

In zsh or any other shell that supports local variables declared with local, you could do

a () {
    local YACY_TIMEOUT=60

    YACY_TIMEOUT=$YACY_TIMEOUT yacy -r -d sth
}

Here, YACY_TIMEOUT would be local to the a function. The injection of the variable as an environment variable in the yacy process happens as in the first example I gave, by preceding the invocation by an assignment.

Now YACY_TIMEOUT is both local and is also available in the yacy process' environment. This would work in any shell that supports using local to declare local variables.

Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

This doesn't do exactly what you want, as it doesn't actually create a new variable in the current shell:

a () {
    YACY_TIMEOUT=60 yacy -r -d std
}

This is the standard syntax for running a command and giving it a particular value of an environment variable. The variable YACY_TIMEOUT, if it exists in the same scope as the body of the a function, would not be modified.

This would work in any POSIX shell.

What this does not do is to allow you to use YACY_TIMEOUT with the "local" value inside the function before calling yacy.

In zsh or any other shell that supports local variables declared with local, you could do

a () {
    local YACY_TIMEOUT=60

    YACY_TIMEOUT=$YACY_TIMEOUT yacy -r -d sth
}

Here, YACY_TIMEOUT would be local to the a function. The injection of the variable as an environment variable in the yacy process happens as in the first example I gave, by preceding the invocation by an assignment.

Now YACY_TIMEOUT is both local and is also available in the yacy process' environment. This would work in any shell that supports using local to declare local variables.