-1

Unable to create environment variables using a tcsh script.

Tried set, but works only inside the script. setenv doesn't work outside the script. export says "command not found" in the terminal I'm trying to run.

#!/usr/intel/bin/tcsh
#set WV "/p/hdk/cad/custom_waveview/O-2018.09-SP2/bin/wv"
setenv WV "/p/hdk/cad/custom_waveview/O-2018.09-SP2/bin/wv"
echo $WV
env $WV "/p/hdk/cad/custom_waveview/O-2018.09-SP2/bin/wv"

I expect the output to be /p/hdk/cad/custom_waveview/O-2018.09-SP2/bin/wv, when i echo the environment variable WV on the terminal, but i am getting the error of undefined variable.

enter image description here

Barmar
  • 741,623
  • 53
  • 500
  • 612
Alan Saldanha
  • 87
  • 2
  • 8

1 Answers1

0

Environment variables are set in the current process and inherited by child processes. You can't set environment variables in a parent process.

You have to use the source command to execute the script. That makes the current shell process execute the script itself, rather than running it in a child process.

source env_vars.tcsh

set is for setting shell variables, not environment variables. export is a bash command (and also other shells based on Bourne Shell syntax), not a tcsh command.

env requires the arguments before the program name to be variable settings in the form name=value, e.g.

env VAR1=val1 VAR2=val2 /p/hdk/cad/custom_waveview/O-2018.09-SP2/bin/wv

It runs the program with those variables added to the environment.

Barmar
  • 741,623
  • 53
  • 500
  • 612