Problems if the else end if


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems if the else end if
# 1  
Old 09-05-2014
Problems if the else end if

I have the following code

Code:
VarSalida = "52" 
VarSalidaCtl = "" 

echo "VarSalida: $ VarSalida" 
echo "VarSalidaCtl: $ VarSalidaCtl" 


if [$ VarSalida == $ VarSalidaCtl] 
***** then 
echo "true" 
***** else 
********** echo "false" 
***** fi

the problem is this

Code:
test [8]: VarSalida: 0403-012 A test command parameter is not valid.

is not able to compare with null value and I nesecito so someone can help me

Last edited by Scrutinizer; 09-05-2014 at 05:44 PM.. Reason: code tags
# 2  
Old 09-05-2014
If the problem is really only that... try replacing ==with -eq
== is for string comparison, -eq for arithmetic test
# 3  
Old 09-05-2014
There need to be space around the single brackets ( and also a single = sign ) and no space after the $-sign and best to have quotes around the variables...
Code:
if [ "$VarSalida" = "$VarSalidaCtl" ]

Of course the asterisks need to go as well.
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 09-05-2014
prueba[8]: [$: not found.

---------- Post updated at 05:39 PM ---------- Previous update was at 05:38 PM ----------

Thanks it worked !!!!!!!!
# 5  
Old 09-05-2014
Quote:
Originally Posted by junior-helper
If the problem is really only that... try replacing ==with -eq
== is for string comparison, -eq for arithmetic test
When comparing decimal numeric strings for equality, the results from:
Code:
[ "$n1" = "$n2" ]
       and
[ "$n1" -eq "$n2" ]

will always be identical as long as there aren't any "leading" zeros at the start of the string or after an initial minus sign

But when one of the two numbers can be an empty string (as in the example given by the OP), the first test will indicate that the two strings are not equal; but the second test will give you a syntax error in some shells (such as bash) because an empty string is not a numeric value. Other shells (such as ksh) will compare them as if the empty string is zero when using -eq.

Some shells accept == as a synonym for = as a test operator, but correctly writen applications will use =, not == in this form of test.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Solaris

Test program running taking much more time on high end server T5440 than low end server T5220

Hi all, I have written the following program and run on both T5440 and T5220 on same OS version. I found that T5540 server takes more time than T5220. Please find below the details. test1.cpp #include <iostream> #include <pthread.h> using namespace std; #define NUM_OF_THREADS 20... (17 Replies)
Discussion started by: sanjay_singh85
17 Replies

2. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

3. Shell Programming and Scripting

Use of Begin IF ,END IF END not working in the sql script

Hi I have written a script .The script runs properly if i write sql queries .But if i use PLSQL commands of BEGIN if end if , end ,then on running the script the comamds are getting printed on the prompt . Ex :temp.sql After connecting to the databse at the sql prompt i type... (1 Reply)
Discussion started by: isha_1
1 Replies

4. Shell Programming and Scripting

Add end of char \n on end of file

Hi, I want to add \n as a EOF at the end of file if it does't exist in a single command. How to do this? when I use command echo "1\n" > a.txt and od -c a.txt 0000000 1 \n \n 0000003 How does it differentiate \n and eof in this case? Regards, Venkat (1 Reply)
Discussion started by: svenkatareddy
1 Replies

5. Shell Programming and Scripting

Need UNIX shell scripting end to end information

Hi, I would like to learn shell scripting in UNIX. Can any one please give me the support and share the information/documents with me. If any documents please post it to aswanikumar_nimmagadda@yahoo.co.in Thanks in advance...!!! (3 Replies)
Discussion started by: aswani_n
3 Replies

6. IP Networking

Looking for an end-to-end network diagnostic utility...

I am looking for a utility (Windows/Linux/Mac) that will allow me to run some test packets across a customer's network (between their client & my server) to identify a list of (or at least a guess of) all protocols and significant network settings that could adversely effect my systems performance... (1 Reply)
Discussion started by: jjinno
1 Replies

7. IP Networking

end-end packet delay?

following is the output from traceroute traceroute 10.1.11.6 traceroute to 10.1.11.6 (10.1.11.6), 30 hops max, 38 byte packets 1 10.129.1.250 (10.129.1.250) 20.618 ms 0.335 ms 0.271 ms 2 192.0.20.1 (192.0.20.1) 0.694 ms 4.660 ms 0.422 ms 3 192.0.40.1 (192.0.40.1) 0.972 ms 1.917 ms 0.873 ms... (4 Replies)
Discussion started by: yogesh_powar
4 Replies

8. UNIX for Advanced & Expert Users

'make' problems (compliation problems?)

I'm trying to compile and install both most recent version of 'make' and the most recent version of 'openssh' on my Sparc20. I've run into the following problems... and I don't know what they mean. Can someone please help me resolve these issues? I'm using the 'make' version that was... (5 Replies)
Discussion started by: xyyz
5 Replies
Login or Register to Ask a Question