testing a null value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting testing a null value
# 1  
Old 03-17-2010
MySQL testing a null value

Hi all,
My input file having the following details,

Code:
sid,worldpar0334,1024,production setup

am storing all values like this

Code:
C1=cut -d "," -f1
C2=cut -d "," -f2
C3=cut -d "," -f3
C4=cut -d "," -f4

so now in above case we have all values, but

if my input file is like this
sid,worldpar0334,,production setup

I ll store the data as above but now C3 doesn't have a value. While testing like this

Code:
if [ -z ${C3} ] ; then
  echo null
fi

while executing am getting a following error in the console,

test.sh[814]: test: 0403-004 Specify a parameter with this command

Even i tried,

Code:
if [ ${C3} = "" ] ; then
  echo null
fi


Kindly let me know how can I test if the value is null in above scenario...

Thanks

Gopal

Last edited by Franklin52; 03-17-2010 at 11:50 AM.. Reason: Please use code tags!
# 2  
Old 03-17-2010
Quote the variable:

Code:
if [ -z "${C3}" ] ; then
  echo null
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting standard out to /dev/null goes to file "/dev/null" instead

I apologize if this question has been answered else where or is too elementary. I ran across a KSH script (long unimportant story) that does this: if ; then CAS_SRC_LOG="/var/log/cas_src.log 2>&1" else CAS_SRC_LOG="/dev/null 2>&1" fithen does this: /usr/bin/echo "heartbeat:... (5 Replies)
Discussion started by: jbmorrisonjr
5 Replies

2. Shell Programming and Scripting

NULL checking

Hi I need to check the output of a string to null. For eg the output I get for $KIT is empty. So want to echo something when the output is empty. How can I do that? Thanks in advance (6 Replies)
Discussion started by: Ananthdoss
6 Replies

3. UNIX for Dummies Questions & Answers

/dev/null 2>&1 Versus /dev/null 2>1

How are these two different? They both prevent output and error from being displayed. I don't see the use of the "&" echo "hello" > /dev/null 2>&1 echo "hello" > /dev/null 2>1 (3 Replies)
Discussion started by: glev2005
3 Replies

4. Shell Programming and Scripting

Insert string 'NULL' where there is a null value

I have an input file having 7 fields delimited by , eg : 1,ABC,hg,1,2,34,3 2,hj,YU,2,3,4, 3,JU,kl,4,5,7, 4,JK,KJ,3,56,4,5 The seventh field here in some lines is empty, whereas the other lines there is a value. How do I insert string NULL at this location (7th loc) for these lines where... (8 Replies)
Discussion started by: zilch
8 Replies

5. Shell Programming and Scripting

Checking for null value

Dear All, I'm glad that I've also joined in this forum. Good work fellas... :b: Keep going...! :) I am having a .csv file where I am reading the values with comma(,) as delimiter. After reading each and every values, I would like to check whether it is empty (say null or blank spaces). How... (4 Replies)
Discussion started by: ganapathi.t
4 Replies

6. Shell Programming and Scripting

compare null with non-null

I've got a very peculiar situation. I'm trying to find out if we can compare null fields with non-null. I've output csv files from SQL and Oracle. I need to compare each field from the files, and then find out any differences. The files usualy have over 500 fields, and send the resule to DBA.... (8 Replies)
Discussion started by: nitin
8 Replies

7. UNIX for Advanced & Expert Users

Null Value

Hello All, I have a file of the format **** 123 abc ABC 456 bcd BCD 789 def 112 ghi GHI 223 jkl 344 mno MNO **** I am trying to extract the lines that have no values in the third field (in this case, this would be 789 def 223 jkl Can anyone please help??... (1 Reply)
Discussion started by: Khoomfire
1 Replies

8. Solaris

null modem for testing

hi all.. sorry for repeating the same question many times, i just set up a null modem, i am using this as reference : DB25 DB9 -- - 2 TD ---- 2 RD 3 RD ---- 3 TD 4 RTS ---- 8 CTS 5 CTS ---- 7 RTS 7 GND ---- 5 GND 6 DSR -+ +--- 4 DTR 8... (0 Replies)
Discussion started by: waterbear
0 Replies

9. Solaris

null modem serial cable for server testing

HI all, i still have a problem when using null modem to see the output from my server(sun ultra en 3000). i followed the instruction from the internet, but it is not working. 1. i am using db9(5 4, 2 rows,put in laptop serial port) and db25(13 12, 2 rows,put in (A) server serial port). 2.... (3 Replies)
Discussion started by: waterbear
3 Replies

10. UNIX for Dummies Questions & Answers

/dev/null

Hi , I am importing some table from /dev/null i dont understand what is /dev/null Sorry i am new to UNIX sam71 (3 Replies)
Discussion started by: sam71
3 Replies
Login or Register to Ask a Question