Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    if statement not working properly

    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

    If file-A* doesn't exist, then the script stops and gives the output 'no match'. I want it to run if this file doesn't exist, and if it does.

    I'm not sure what I'm doing wrong. Any advice would be appreciated.

  2. #2
    i don't know much about c-shell, but you could do something hideous like this:

    # 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
    Last edited by atreyu; 06-22-2012 at 11:38 PM. Reason: changed == to !=

  3. #3
    Linux User Krendoshazin's Avatar
    Join Date
    Feb 2005
    London, England
    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:
    Last edited by Krendoshazin; 06-23-2012 at 09:07 AM.

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts