0

I have a small script that performs the following actions. I have simplified it for this example.

set logfile=$HOME/LOG/output.log
find execute.sh -type f -exec csh -c '"$1" >& "$logfile" &' {} \;

The issue is that the find command is not expanding the $logfile value. Instead it is giving me an error

logfile: Undefined variable.

I am not that familiar with csh, nor have I done scripting for quite a while, but is it possible to escape this or otherwise gain access to the value in the command?

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
McArthey
  • 1,614
  • 30
  • 62

2 Answers2

1

logfile is not an environment variable, so it doesn't exist in the shell started by the -exec primary. You can either use setenv:

setenv logfile "$HOME/LOG/output.log"

or change the quotes so that $logfile is expanded before passing the command to csh. It's not clear to me how $1 is supposed to be set, though.

chepner
  • 497,756
  • 71
  • 530
  • 681
0

[ I recognize how old this question is, but it still shows up early in searches ] In plain C-shell (/bin/csh, and emulators which restrict syntax to match), the variable setting must be delimited with spaces, thus

set logfile = $HOME/LOG/output.log

In Tcsh, the spaces are optional. If your script was written for strict C-shell compatibility, your first line ended up setting a rather peculiar variable to an empty string: on my Mac, it would have been logfile=/Users/kelsey/LOG/output.log = "".