0

The set command works fine when I type it like this:

echo $0
/usr/bin/tcsh
echo $SHELL
/usr/bin/tcsh
set START_TIME=`date +%s`
echo $START_TIME
1499360060

However, it doesn't work when I call it explicitly in tcsh like this:

/usr/bin/tcsh -i -f -c 'set START_TIME=`date +%s`'
echo $START_TIME
START_TIME: Undefined variable.

I tried to do this with setenv at first, but then realized that child process cannot run setenv command. So, I figured set is the way to go. Please advise if there's another better way to go about this. Thanks.

0

1 Answer 1

1

The issue is that you are setting the variable in a subshell which then terminates, taking your variable with it. To demonstrate:

$ /bin/tcsh -ifc 'set VARIABLE=foo; echo $VARIABLE'; echo ${VARIABLE-blank}
foo
blank

(My main shell is bash; the second echo uses a bashism to give a default value for an undefined or null variable expansion)

Not the answer you're looking for? Browse other questions tagged .