--
=================================================================
> case $1 in
> *-*) echo "Contains 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
case $1 inQuote:>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?
--
bringing you boring signatures for 17 years
For parsing command line arguments it may also be a
good idea to consider the ?getopts? command.
Best regards - Juergen
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,
5. delete a line from file (same string problem)
10. Returning only 1 string problem
11. Searching for string problems
13. string problem