Sponsored Content
Top Forums Shell Programming and Scripting How to compare a parameter to a string Post 302385743 by shira on Saturday 9th of January 2010 01:14:41 PM
Old 01-09-2010
ok, I discovered the problem, but it's very odd.
At the beginning of the script I defined parameter.
I echoed it right after the definition and it was okay.

I echoed it right before the if like you said, but it showed me that inside parameter, instead of string, there was 0!

It's as if parameter was changed throughout the script, but I didn't touch it until I got to the if part!

Do you have any idea why this thing could happen?

Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing a string parameter to a function

I need to pass a parameter to a function in a script. My parameter is a string. When I display the parameter within my function, I only get the first word from string I pass in. How can I make the function receive the whole string (and not terminate at the first space it encounters)?. part of... (1 Reply)
Discussion started by: fastgoon
1 Replies

2. Shell Programming and Scripting

replacing a string in a file with command line parameter

Hello, I am trying to replace a string with a paramter given along with the script. I am replacing application1 to application2 with the script: ./change_app.sh application2 change_app.sh: #!/bin/ksh grep $1 applications.dat 2>&1 >/dev/null echo $1 file=pckage.new sed 's/Name:... (5 Replies)
Discussion started by: chiru_h
5 Replies

3. Shell Programming and Scripting

Check if parameter passes in contains certain string

Hi Guys, I am writing a Unix script which accepts a directory path as parameter $1 so something like /user5.data/WA/01 will be passed in. I want to determine if the directory path passed in contains "WA" as above (because then I need to do something specific if it does) What is the... (9 Replies)
Discussion started by: bcunney
9 Replies

4. UNIX for Dummies Questions & Answers

How to compare a string with IP

Hi, I have a variable with value tmp2=123.45.175.243, I am taking this value from a network file. In the script I need to check whether the variable has only numerals and .(dot). if ..." ] then printf "SUCCESS\n" else printf "FAILED\n" fi doesnt work, is there a alternate... (1 Reply)
Discussion started by: happyrain
1 Replies

5. Shell Programming and Scripting

How to compare a command line parameter with -- in shell scripting

Hi, I need to check if a parameter provided at the command line is equal to --.How can i do that ? Please help me. Thanks and Regards, Padmini (4 Replies)
Discussion started by: padmisri
4 Replies

6. Shell Programming and Scripting

String compare

Hi, I have file like below, Srinivas Jala Srinivas Jala AA Srikanth ML Srikanth ML KK Vijay Kumar Dha Vijay Kumar Dha JJ i want to compare like "Srinivas Jala" word in same line, if i found i shoud get some like found, or not found. Pls help to get the code. (3 Replies)
Discussion started by: Srinivas.Jala
3 Replies

7. Shell Programming and Scripting

How to pass string as a parameter in a script

Hi friends. i am newbie to shell scripting. I need to create a script where i will be passing 2 parameters to the script and based on that it should work. For ex: start_proc a 2 or start_proc b 2 start_proc a 2 --- this should bring up 2 processes as i define inside the script. start_proc... (2 Replies)
Discussion started by: friscouser
2 Replies

8. Shell Programming and Scripting

Check parameter is number or string

Hey I'm new in linux, I'm looking for a code to check whether the parameter is a number or a string. I have already tried this code: eerste=$(echo $1 | grep "^*$">aux) if But it doesn't work.:confused: Thanks (2 Replies)
Discussion started by: Eclecticaa
2 Replies

9. Shell Programming and Scripting

Passing string as a input parameter for a shell script

Hi i have a shell script which needs a string as an input parameter. How to pass the string param as an input? In command line am running the script. for e.g., a="who is a buddy?" sh sample.sh $a Inside the script i get this input param as $1 but only the value "who" is accepted... (12 Replies)
Discussion started by: vidhyaS
12 Replies

10. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies
string(3)						     Library Functions Manual							 string(3)

NAME
strcat, strcmp, strcpy, strdup - Perform operations on strings LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <string.h> char *strcat( char *s1, const char *s2); int strcmp( const char *s1, const char *s2); char *strcpy( char *s1, const char *s2); char *strdup( const char *s1); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: strcat(), strcmp(), strcpy(): XSH4.2 strdup(): XSH4.2 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
In strcat(), specifies the destination string for appending; in strcmp(), specifies the first of two strings to compare; in strcpy(), spec- ifies the destination string for the copying; and in strdup(), specifies the string to be duplicated. In strcat(), specifies the string to be appended to s1; in strcmp(), specifies the second of two strings to compare; and in strcpy(), specifies the source string for the copy- ing. Note [Tru64 UNIX] If you pass a NULL pointer as one of the const char * or char * parameters of a string manipulation function, the function generates a segmentation violation. To avoid the segmentation violation and cause the function to return zero, change the NULL pointer treatment for the process before issuing the call to the string manipulation function, as follows: Include the system header file sys/uswitch.h. Call the uswitch function, as described in the uswitch(2) reference page. The following program illustrates this procedure: #include <stdio.h> #include <sys/types.h> #include <sys/uswitch.h> main() { size_t retval; int uswitch_val; uswitch_val = uswitch(USC_GET,0); uswitch(USC_SET, uswitch_val | USW_NULLP); retval = strdup(NULL); DESCRIPTION
The strcat() function appends a copy of the string pointed to by the s2 parameter (including the terminating null byte) to the end of the string pointed to by the s1 parameter. The initial byte of s2 overwrites the null byte at the end of the string pointed to by s1. When operating on overlapping strings, the behavior of this function is unreliable. The strcmp() function compares the string pointed to by the s1 parameter to the string pointed to by the s2 parameter. The sign of a nonzero value returned by strcmp() is determined by the sign of the difference between the values of the first pair of bytes (both inter- preted as unsigned char) that differ in the two compared objects. The strcmp() function compares strings based on the machine collating order. It does not use the locale-dependent sorting order. Use the strcoll() or wcscoll() functions for locale-dependent sorting. The strcpy() function copies the string pointed to by the s2 parameter (including the terminating null byte) to the location pointed to by the s1 parameter. When operating on overlapping strings, the behavior of this function is unreliable. The strdup() function returns a pointer to a new string that is an exact duplicate of the string pointed to by the s1 parameter. The mal- loc() function is used to allocate space for the new string. RETURN VALUES
On successful completion, the strcat(), strcpy(), and strdup() functions return a pointer to the resulting string. Otherwise, these func- tions return a null pointer. The strdup() function sets errno to indicate the error. On successful completion, the strcmp() function returns an integer whose value is greater than, equal to, or less than 0 (zero), according to whether the s1 string is greater than, equal to, or less than the s2 string. ERRORS
If the strdup() function fails, errno may be set to the following value: Insufficient storage space is available. RELATED INFORMATION
Functions: malloc(3), memccpy(3), setlocale(3), strchr(3), strcoll(3), strlen(3), strncasecmp(3), strncat(3), strncmp(3), strncpy(3), strp- brk(3), strspn(3), strtok(3), strstr(3), strxfrm(3), swab(3), uswitch(2), wcscat(3), wcscmp(3), wcscpy(3) Standards: standards(5) delim off string(3)
All times are GMT -4. The time now is 09:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy