String Problem

String Problem

Post by Can Chan » Mon, 13 May 2002 06:59:47



Hi, I'm trying to write a shell script for sh and I need to check whether
the command line argument $1 contains the character "-" (hyphen) as its
first character. I've tried so many ways but none worked for me. anyone
know how this could be done?
Thanks so much!
 
 
 

String Problem

Post by Chris F.A. Johnso » Mon, 13 May 2002 07:18:18



> Hi, I'm trying to write a shell script for sh and I need to check whether
> the command line argument $1 contains the character "-" (hyphen) as its
> first character. I've tried so many ways but none worked for me. anyone
> know how this could be done?

        case $1 in
            *-*) echo "Contains hyphen" ;;
            *) echo "No hyphen"" ;;
        esac

--

        =================================================================



 
 
 

String Problem

Post by Chris F.A. Johnso » Mon, 13 May 2002 07:22:12




>> Hi, I'm trying to write a shell script for sh and I need to check whether
>> the command line argument $1 contains the character "-" (hyphen) as its
>> first character. I've tried so many ways but none worked for me. anyone
>> know how this could be done?

>    case $1 in
>        *-*) echo "Contains hyphen" ;;

    That should be (to check that the first character is a hyphen):

        -*) echo "Begins with hyphen" ;;

    Of course, if you want to parse options on the command line, you
    should look at getopts.

Quote:>        *) echo "No hyphen"" ;;
>    esac

--

        =================================================================


 
 
 

String Problem

Post by those who know me have no need of my nam » Mon, 13 May 2002 07:16:25



Quote:>Hi, I'm trying to write a shell script for sh and I need to check whether
>the command line argument $1 contains the character "-" (hyphen) as its
>first character. I've tried so many ways but none worked for me. anyone
>know how this could be done?

case $1 in
  -*) # has leading hyphen
      ;;
  *)  # does not
      ;;
esac

--
bringing you boring signatures for 17 years

 
 
 

String Problem

Post by Juergen Sal » Mon, 13 May 2002 07:45:34



> I need to check whether the command line argument $1 contains
> the character "-" (hyphen) as its first character.

case $1 in
    -*) echo '$1' starts with - ;;
    *)  echo '$1' does not start with - ;;
esac

For parsing command line arguments it may also be a
good idea to consider the ?getopts? command.

Best regards - Juergen

 
 
 

1. C string problem

You haven't allocated memory for temp.  Currently temp is a pointer
to memory.  But you haven't set it up to point to anything.

In the simple case, you need something like this
   static char temp[MAXSIZE];
   ...
   if (pos+len-1 > MAXSIZE) {
        printf("too large for internal buffer\n");
        return buff;
   }

Of course this limits the size of characters.  You can use dynamic
memory allocation to increase the size of the buffer if needed.
That's a lot more code, but it works over a wider range of cases.

-paul-
--


voice: +1 301 975-4794              fax: +1 301 926-3696
Web: http://hissa.ncsl.nist.gov/~black/black.html               KC7PKT

2. Hey,

3. vuzkern-/strings-Problem

4. changing video cards

5. delete a line from file (same string problem)

6. Problems with socket

7. jdk1.4.0 p1 string problem

8. HELP: HDD-Probs

9. vuzkern-/strings-Problem

10. Returning only 1 string problem

11. Searching for string problems

12. version string problem

13. string problem