home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 6.9 Special C Shell Variables Chapter 6
Shell and Environment Variables
Next: 7. Setting Your Shell Prompt
 

6.10 Running a Command with a Temporarily Different Environment

Quite a few UNIX commands set themselves up by reading the environment. For example, the vi editor reads startup commands from the EXINIT environment variable. Sometimes, you'll want to override the setting of an environment variable for just one command. There's an easier way than setting the variable to a different value and changing it back after you run the command:

  • In the Bourne shell, type:

    $ 
    
    VARNAME=value command args
    
    

  • In the C shell on UNIX systems that have the env command, type:

    % 
    
    env VARNAME=value command args
    
    

  • Or, in any C shell, use a subshell ( 13.7 ) like this:

    % 
    
    (setenv VARNAME value; command args)
    
    

For example, if your EXINIT variable has:

set wrapscan showmatch number

and you want to add nowrapscan to the end of it just this once, you could type (to the Bourne shell):



$
 

$ 

EXINIT="$EXINIT nowrapscan" vi afile

After that vi command ran, EXINIT wouldn't contain nowrapscan .

For a great example of this technique, see article 6.7 .

- JP


Previous: 6.9 Special C Shell Variables UNIX Power Tools Next: 7. Setting Your Shell Prompt
6.9 Special C Shell Variables Book Index 7. Setting Your Shell Prompt

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru