Windows text files terminate lines of text with a carriage return and a line feed (CR/LF); all Unix-like systems use only a LF to terminate text lines. The CR character can play havoc sometimes.
vim will show you control characters in a text file (a CR is a control character) that "shouldn't" be there. If you don't have any, so much the better -- just something to be on the look-out for. You won't see horizontal tab (HT) or line feed (LF) because they
are supposed to be there, eh?
It's pretty common practice that a shell program source code file be named "something.sh" (as you would name a C-language source code file "something.c" and so on with other programming languages (keep in mind that shell programming languages, Bourne, Korn, C-Shell, BASH) are programming languages with specific grammar and syntax rules. It's also pretty common practice that all source code files that matter; i.e., they're going to be used for a while rather than just a one-off quickie, be stored in a source code control system; e.g., CVS, so they can be edited as necessary over time with changes stored in the source code control system.
The
make utility will, by default, create an executable shell program from a source code file simply by executing
where "name.sh" is the source code and the generated file will be "name" (there are hundreds of shell programs that are part of your distribution that are generated from source exactly like this).
In the case of your file, I saved it as
daq.sh. If I
I can then simply enter
and it'll execute (so I would not need the
tcsh daq.sh, only
daq.
If you're interested, take a look:
Code:
cd /usr/bin
file * | grep shell
You'll see a large number of files that are "POSIX shell script text executable" or something similar to that.
One of the reasons that people have stopped using C-Shell is that it does thing for you that you probably don't want done; e.g., if a C-Shell user has a
.chsrc file in their home directory, every time you hit the return key to execute something the content of that
.cshrc file is executed (and you don't want that to happen sometimes). It's hard to get around that and I'm not sure that using the
-f option embedded in the source code file will prevent it (maybe doing
may be an option). I abandoned C-Shell about 20 years ago so I really don't have much of a feel for what sort of naughty behavior it may get up to nowadays. The company I retired from a few years ago insisted that users' use C-Shell and used a system-wide ".cshrc" so they could not alter their environments (PATHs, defaults and the like). Caused problems, that, and took some gyrations to get around (as a developer, I used Korn Shell so that "magic" didn't affect my work). Keeping in mind that a child process inherits the parent processes environment in C-Shell, that may be something to look at.
About the only thing I can think of (and remember, I'm not a C-Shell programmer) is that you're getting something illegal from the command line when you enter the number at the prompt -- you might want to try displaying the entry to see what you're actually getting, say above the line
Code:
echo -n "Please enter the number of the current or most recently completed run: "
set runNum = "$<"
The only other thing I can think of is -- and this is kind of out there -- to enclose variables in braces so
$runNum becomes
${runNum}. Might matter, might not, but the braces do a good job of isolating variables from any possible interference.
Bottom line, though, is this: my environment is Korn Shell, not C-Shell and your code appears to work as you expect on my system. That would lead me to conclude that you have some strange and wonderful environment settings getting done for (or, you know, to) you that are causing problems. Just ain't much else left. Take a hard look at your
.login and
.cshrc files and see what's going on in them. Also, from a shell prompt, try
Code:
env | sort | pg (or | more)
and see what's what.
Then, do a one-liner (well, maybe two-liner)
Code:
#!/bin/tcsh -f
env | sort | pg
and compare the two -- instead of piping into
pg, redirect output from the above into files and use
diff to see if there's something biting you.
And, finally, do a quick re-write in Bourne, Korn or BASH and see what you get.
Hope this helps some.