> I'm just learning Unix in an environment which runs FreeBSD
> 2.2-971230-SNAP. The shell is csh.
> I have a 'test' file which it seems won't set variables. It contains:
> set logdate = `date "+%Y%m%d"`
> echo $logdate
> echo $logdate > test.dat
> The permissions are u:rwx, and when I run it as ./test, a blank line is
> echoed to the terminal screen. The test.dat file contains only a blank
> Yet, if I execute each of those lines "live" from the terminal, it sets
> the variable correctly, echoes the value, then puts the value into the
> test.dat file.
> I'm guessing the problem is that the shell script is not storing or
> reading values from variables.
> What's going on here?
Try this in your script:
set logdate = (`date +%Y%m%d`)
echo $logdate | tee test.dat
Refer to the manpage for csh, esp. the section "Expressions"
for a discussion on precedence of + % ` and ( as well as the
"Lexical structure", "Command substitution" and
"Quotations ..." sections.
Your own $HOME/.cshrc and $HOME/.login might afford some
You might also like to lurk in comp.unix.shell for some
very interesting and enlightening discussions on scripting.
If you post your question there, certain pedants would
recommend against naming your script "test" (there's already
a /bin/test) and/or for using csh for scripting at all (some
folks read a certain article in O'Reilly's "Unix Power
Tools" and take it as Gospel)
I won't bug ya, though :)
If you're /really/ interested in scripting, i recommend getting
a copy of "UNIX Shell Programming" by Stephen G. Kochan and
Patrick H. Wood. My copy is so old i don't know if its publisher
(Hayden Books) or ISBN are still valid.
Applicants must have at least five years' experience with Windows 98 ...
remove NO_SPAM. from address to reply