#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    49
    Rep Power
    13

    plese help-comparison string


    i want to search for file that start with file200411*. i can't pass the variable. should i use grep?
    the output will appear as "nor exist" although there is a file in a directory
    so..please help

    #!/bin/sh

    yr=2004
    mth=11

    for file in ls file*
    do
    if [ "$file" = "file$yr$mth*.txt" ]
    then
    echo "file exist, $file"
    else
    echo "file not exist"
    fi
    done
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,198
    Rep Power
    17
    use 'if' for numerical tests
    use 'case' for all other
    Code:
    for file in `ls`
    do
        case $file in file$yr$mth*.txt) XXX= ;; *)  XXX=not ;; esac
        echo "file $file does $XXX exist"
    done
    Last edited by guggach; December 30th, 2004 at 07:17 AM. Reason: typo
  4. #3
  5. Introspective
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    3,317
    Rep Power
    113
    Originally Posted by izza_azhar
    i want to search for file that start with file200411*. i can't pass the variable. should i use grep?
    the output will appear as "nor exist" although there is a file in a directory
    so..please help

    #!/bin/sh

    yr=2004
    mth=11

    for file in ls file*
    do
    if [ "$file" = "file$yr$mth*.txt" ]
    then
    echo "file exist, $file"
    else
    echo "file not exist"
    fi
    done

    why not just use find?
    Code:
    find . -name "file200411*" -print
    christo

    or does this definititel h
    This is me: http://chris.uk.com

IMN logo majestic logo threadwatch logo seochat tools logo