質問

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?

役に立ちましたか?

解決

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.

他のヒント

[ 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 = "".

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top