Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Ksh Why Won't IF Statement work? Post 302183149 by developncode on Tuesday 8th of April 2008 12:11:41 PM
Old 04-08-2008
Question Ksh Why Won't IF Statement work?

I'm trying to figure out why this if statement won't work:
Code:
            if [[ $zipcode != +([0-9)] || $zipcount != 6 ]]
            then
	       echo ${myline}
	       echo "ZIPCODE WARNING! ${zipcode} ${zipcount}"
            fi
	    if [[ $state != ?? || $state != +([A-Z)] ]]
	    then
               echo ${myline}
	       echo "STATE WARNING! ${state}"
	    fi
	    if [[ $city < ??? || $city != +([A-Z)] ]]
	    then
	       echo ${myline}
               echo "CITY WARNING!"
            fi

These conditional statements basically check the ZIPCODE variable and if it is NOT a digit or if the ZIPCOUNT variable doesn't equal 6 it prints out a Warning for the zipcode. The second conditional if statement checks the STATE variable and if it is NOT 2 characters long or if it is NOT a character from A to Z then it prints out a Warning for the state. Lastly the third conditional if statement checks the CITY variable and if it is LESS THAN 3 characters long or if it is NOT a character from A to Z then it prints out a Warning for the city.

I have no idea why this isn't working please help.

the whole script is:

Code:
#!/bin/ksh
integrity=1
filename=~/fielded.complete
while [ $integrity = 1 ]
do
echo "Reprint Request File: "$filename
echo ""
   { while read myline
   do
      if [[ $myline != H* && $myline != T* ]]
      then
         if [[ $myline = D* ]]
         then
	    zipcode=$(echo ${myline} | sed 's/^[ \t]*//;s/[ \t]*$//')
            zipcode=${zipcode#${zipcode% *}}
	    zipcount=$(echo ${zipcode} | wc -m)          
	    state=${myline%$zipcode*}
	    state=$(echo ${state} | sed 's/^[ \t]*//;s/[ \t]*$//')
	    state=${state#${state% *}}
            city=${myline%$state*}
            city=$(echo ${city} | sed 's/[ \t]*$//')
	    city=${city#${city% *}}
	  
            if [[ $zipcode != +([0-9)] || $zipcount != 6 ]]
            then
	       echo ${myline}
	       echo "ZIPCODE WARNING! ${zipcode} ${zipcount}"
            fi
	    if [[ $state != ?? || $state != +([A-Z)] ]]
	    then
               echo ${myline}
	       echo "STATE WARNING! ${state}"
	    fi
	    if [[ $city != ??? || $city != +([A-Z)] ]]
	    then
	       echo ${myline}
               echo "CITY WARNING! ${city}"
            fi
         fi 
      fi
   done } < $filename
((integrity=0))
done

edit by bakunin: added code-tags for better readability of the program text parts. Please do so yourself the next time.

Last edited by bakunin; 04-09-2008 at 08:26 AM..
 

10 More Discussions You Might Find Interesting

1. Solaris

(Yet) Another newbie qstn - X-server won't work!

Hi everyone, I've just bought a sun ultra 60 and am a bit of a unix newbie, so bear with me here! I've just completed a fresh install of Solaris 9 and everything was going well until the machine rebooted. When the system is coming up, it prints the followinf message on-screen: The X-server... (7 Replies)
Discussion started by: alarmcall
7 Replies

2. UNIX for Dummies Questions & Answers

why won't this Work?

hey programmers! 1-why won't gcc accept as an argument? i tried the recommendations on the man page of getch(),..etc. nothing worked. 2-why it won't see <iostream> && <fstream> even if i implemented the function as follow std::cout<<"..etc"<<endl; 3-after i type this code in it gives... (6 Replies)
Discussion started by: mbabeli
6 Replies

3. UNIX for Dummies Questions & Answers

sed won't work

Hi All, can anybody tell me what's wrong with this code? # SEARCH replaced by REPLACE #!/bin/bash SEARCH="95$$ 0 t" REPLACE="95$$ 1 t" for I in `ls *000.inp | cut -c-12`; do echo $I sed 's/$SEARCH/$REPLACE/' ${I}-000.inp > ${I}-100.inp done It don't replace the string... (5 Replies)
Discussion started by: f_o_555
5 Replies

4. OS X (Apple)

Why won't the at command work in Mac OS X?

I typed: echo "echo hi > at_log.txt" | at now +1minute to test the at command on my terminal. I got the message: job 8 at Thu Feb 25 18:42:00 2010 I waited for a minute but nothing happened. I tried listing at_log.txt, but it said there was no such file. Am I doing something... (2 Replies)
Discussion started by: Ultrix
2 Replies

5. Shell Programming and Scripting

Exporting my dynamical variable won't work?

Even though the idea "might" not be great I still wrote this piece of code to get practice.. Which means that it is the CODE that matters here. Anyways; The intension is to create a program(or do we call it script?) that searches recursively through a folder to find a file - stored in a... (4 Replies)
Discussion started by: Pesk
4 Replies

6. UNIX for Dummies Questions & Answers

OpenSolaris, Wireless won't work, help please!

I just installed a fork of opensolaris, and I really like it. I would hate going back to Ubuntu, But one issue, I cannot get my Dell Wireless 1450 Wireless USB Adapter working. On Ubuntu 10.4 I just installed nonfree firmware, but I guess it doesn't work that way on Solaris, any help would be... (5 Replies)
Discussion started by: Stormos
5 Replies

7. Solaris

string extraction won't work. Why?

#!/usr/bin/ksh set -x testfile=my.test.file.flag echo ${testfile: (-4)} #/home/maldohe/scripts/spawn1& sleep 3 echo myspawn is now ending exit Background: I am trying to extract the word flag from anf given file name. This is a demo script that I am working on to fix a production issue.... (8 Replies)
Discussion started by: Harleyrci
8 Replies

8. BSD

Install cd won't work

Hi! I'm sure that somebody here installed freeBSD from a download of a virtual disc (.iso). But I made 5 downloads of 5 differents freeBSD installation (and no one has worked).Can somebody tell me where to download and how (if needed) to prepare the cd? (8 Replies)
Discussion started by: maxum
8 Replies

9. UNIX for Dummies Questions & Answers

Images won't work?

Hello, Images won't work on UNIX when I try posting them on my website I'm working on. It doesn't show the image, and it's simply erroring. Help! Thanks! (5 Replies)
Discussion started by: yazan
5 Replies

10. IP Networking

NAT via iptables - Won't work!!

Hi guys I'm running on debian on a small embedded system. I have a ppp interface that is connected to the internet (and works). My unit also has wifi access point (which works and I can connect to it). I want to allow connections to the wifi to be able to use the internet from ppp0... (1 Reply)
Discussion started by: alirezan1
1 Replies
MAXDB_REAL_ESCAPE_STRING(3)						 1					       MAXDB_REAL_ESCAPE_STRING(3)

maxdb_real_escape_string - Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the con-
nection

       Procedural style

SYNOPSIS
string maxdb_real_escape_string (resource $link, string $escapestr) DESCRIPTION
Object oriented style string maxdb::real_escape_string (string $escapestr) This function is used to create a legal SQL string that you can use in an SQL statement. The string escapestr is encoded to an escaped SQL string, taking into account the current character set of the connection. Characters encoded are ', ". RETURN VALUES
Returns an escaped string. EXAMPLES
Example #1 Object oriented style <?php $maxdb = new maxdb("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } $maxdb->query("CREATE TABLE temp.mycity LIKE hotel.city"); $city = "'s Hertogenbosch"; /* this query will fail, cause we didn't escape $city */ if (!$maxdb->query("INSERT into temp.mycity VALUES ('11111','$city','NY')")) { printf("Error: %s ", $maxdb->sqlstate); } $city = $maxdb->real_escape_string($city); /* this query with escaped $city will work */ if ($maxdb->query("INSERT into temp.mycity VALUES ('22222','$city','NY')")) { printf("%d Row inserted. ", $maxdb->affected_rows); } $maxdb->close(); ?> Example #2 Procedural style <?php $link = maxdb_connect("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } maxdb_query($link, "CREATE TABLE temp.mycity LIKE hotel.city"); $city = "'s Hertogenbosch"; /* this query will fail, cause we didn't escape $city */ if (!maxdb_query($link, "INSERT into temp.mycity VALUES ('11111','$city','NY')")) { printf("Error: %s ", maxdb_sqlstate($link)); } $city = maxdb_real_escape_string($link, $city); /* this query with escaped $city will work */ if (maxdb_query($link, "INSERT into temp.mycity VALUES ('22222','$city','NY')")) { printf("%d Row inserted. ", maxdb_affected_rows($link)); } maxdb_close($link); ?> The above example will output something similar to: Warning: maxdb_query(): -5016 POS(43) Missing delimiter: ) <...> Error: 42000 1 Row inserted. SEE ALSO
maxdb_character_set_name(3). PHP Documentation Group MAXDB_REAL_ESCAPE_STRING(3)
All times are GMT -4. The time now is 10:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy