Results 1 to 3 of 3
I'm new to c shell scripts and am currently trying to edit a script to include an if statement. I've created: cd $DIR_1 if (-e $DIR_rawdata/file-A*) then script1.pl else script2.pl ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 06-22-2012 #1
- Join Date
- Jun 2012
if statement not working properly
if (-e $DIR_rawdata/file-A*) then
If file-A* doesn't exist, then the script stops and gives the output 'no match'. I want it to run script2.pl if this file doesn't exist, and script1.pl if it does.
I'm not sure what I'm doing wrong. Any advice would be appreciated.
- 06-22-2012 #2
- Join Date
- May 2011
i don't know much about c-shell, but you could do something hideous like this:
#!/bin/csh # here i assume the full directory path to the file is /tmp/foo/rawdata/file-A.whatever set DIR_1 = /tmp/foo cd $DIR_1 set val = `echo ./rawdata/file-A*` if ( $val != "" ) then script1.pl else script2.pl endif
Last edited by atreyu; 06-22-2012 at 11:38 PM. Reason: changed == to !=
- 06-23-2012 #3
Is the file actually called file-A*? I think you should reconsider the use of * in a filename as this is a wildcard, and it could cause a whole number of problems. If you accidentally put a space between file-A and * while using rm, then you can kiss all your files in that directory good bye. I'm fairly sure this is also why your script isn't working.
Additionally, I would recommend using something such as BASH for your scripting needs. Here's a lengthy post on the lack of functionality of CSH: http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
Last edited by Krendoshazin; 06-23-2012 at 09:07 AM.