Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an environment variable for just one command in csh/tcsh

Tags:

csh

tcsh

In bash, I can set a temporary environment variable for just one command like this:

LD_LIBRARY_PATH=/foo/bar myprogram

Can I do something similar in csh / tcsh? I could do

setenv LD_LIBRARY_PATH /foo/bar; myprogram; unsetenv LD_LIBRARY_PATH

, but that will lose any previous value the variable had.

like image 874
Tor Klingberg Avatar asked May 10 '11 07:05

Tor Klingberg


People also ask

How do I set environment variables in tcsh shell?

You can use the set or setenv command under c shell (tcsh/csh) to set an environment variable. Setting or modifying PATH. Set your default (preferred) editor. Set pager and more.

How can you set environment variables from the command-line?

To set an environment variable, use the command " export varname=value ", which sets the variable and exports it to the global environment (available to other processes). Enclosed the value with double quotes if it contains spaces. To set a local variable, use the command " varname =value " (or " set varname =value ").


1 Answers

In csh, you can either try env:

% env LD_LIBRARY_PATH=/foo/bar myprogram

or, a subshell:

% (setenv LD_LIBRARY_PATH /foo/bar; myprogram)
like image 72
dogbane Avatar answered Oct 16 '22 19:10

dogbane