Zsh alternativa ao truque de atribuição rápida e herança do bash

1

Existe um truque disponível no bash que lhe permite definir a variável de ambiente para o processo filho e executá-lo em uma única linha, mantendo os valores originais da variável no shell. Por exemplo, para definir as variáveis de ambiente "LANG" e "FOO" e depois executar "gedit", usaríamos o seguinte comando (from Docs do Ubuntu ):

LANG=he_IL.UTF-8 FOO=bar gedit

Não funciona em zsh.

Existe uma alternativa similarmente simples?

    
por Michael Pankov 11.02.2013 / 16:03

1 resposta

2

O que você descreve funciona da mesma forma no Zsh e no Bash. De o manual :

A simple command is a sequence of optional parameter assignments followed by blank-separated words, with optional redirections interspersed. The first word is the command to be executed, and the remaining words, if any, are arguments to the command.

If a command name is given, the parameter assignments modify the environment of the command when it is executed. (…)

… e no Bash :

When a simple command is executed, the shell performs the following expansions, assignments, and redirections, from left to right.

  1. The words that the parser has marked as variable assignments (those preceding the command name) and redirections are saved for later processing.

If no command name results, the variable assignments affect the current shell environment. Otherwise, the variables are added to the environment of the executed command and do not affect the current shell environment

    
por 11.02.2013 / 17:13