Results 1 to 4 of 4

Thread: Wildcards KSH

  1. #1
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    421

    Unanswered: Wildcards KSH

    Uhm, probably a stupid question....

    I want to find out if a string is in a variable.
    myvar='thisisnamliamsstupidquestion'
    if [ "$myvar" like "namliam" ]
    would return a true or maybe a 7 as that is the character it is starting.

    Just searching (a bit quickly) I am not finding it. Any bright minds out there? As its CoB for me... Hope to find a nice answer in the morning

    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    Location
    Rome, Italy
    Posts
    81

    Wink

    hi,
    actually I don't know any way for such a string manipulation in ksh. For that it would be better to use perl. But for your pupose I think it could help this:

    ------------------------------------------------
    myvar='thisisnamliamsstupidquestion'
    echo $myvar|grep "namliam"
    if test $? -eq 0
    then
    echo "String found"
    else
    echo "String NOT found"
    fi
    --------------------------------------------------

    I hope it works for you.
    ducasio

  3. #3
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    421

    Thanks

    Tho I found another way of dealing with my problem using AWK, not the nicest of solutions, but it works.... for now.

    Also I put this to a function, so if ever things change I can do it all over without problems.

    In this particular case I would be testing 5 or 6 options. I thought of doing the grep thing... But for 5 to 6 options... A bit of a "nail biter", so I went with the AWK (one line) function.

    Thanks again.

  4. #4
    Join Date
    Aug 2004
    Location
    Rome, Italy
    Posts
    81

    Talking

    Very good then.


Posting Permissions

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