Null handling in scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Null handling in scripts
# 1  
Old 01-20-2005
Question Null handling in scripts

Hi,
I face some problem with handling of nulls. I declare a variable - say i - and intialise to 0. Later I read it from console, wherein if I dont give any variable and press return key, I get this error:
"0403-004 Specify a parameter with this command"

Is there anyway to handle this error?

Thanks in advance..

MohanPrabu
# 2  
Old 01-20-2005
Assuming that you are writing a shell script

Code:

if [ $1 = " " ]
then
echo "No Arguments"
else
<commands you want to execute>
fi
# 3  
Old 01-20-2005
Or for true "nulls" and unset variables, etc..

[ -z "$i" ] && echo "nothing here"

Cheers
ZB
# 4  
Old 01-20-2005
You can also default your variables using the builtins in Korn.

Code:
${parameter:-word} 
- If parameter is null or unset, word is substituted for parameter.
The value of parameter does not change.

${parameter:=word} 
- If parameter is null or unset, parameter is set to the value of word.

${parameter:?message}
- If parameter is null or unset, message is printed to standard error.
This checks that variables are set correctly.

${parameter:+word}
 - If parameter is set, word is substituted for parameter.
 The value of parameter does not change.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Handling scripts in two different servers

Hi , My Script work as below 1- On server 1 execute script1.sh , through this script one parameter file is generated as file.txt this is to transfer on server 2 2- After reaching on server2 other shell script script2.sh execute using parameter file file.txt This generate file... (1 Reply)
Discussion started by: kaushik02018
1 Replies

2. Shell Programming and Scripting

Handling null Integer/string variables

I kind of found out the hard way that I am not able to manipulate the null value, the long silence that happens when there is no value returned. I am looking for PIDs, and when there is no PID return, I wanted to handle this special scenario. Here is my script. #!/bin/bash LAN_VARIABLE=... (7 Replies)
Discussion started by: lan123
7 Replies

3. 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

4. Shell Programming and Scripting

Null Handling in Until loop. . .loop won't stop

Hi Im running this script, which is supposed to find the max value build some tables and then stop running once all the tables are built. Thing is , it keeps assigning a null value to $h and then $g is null so it keep building tables i.e. testupdateNUL. How can I stop this? Here is what I have: ... (4 Replies)
Discussion started by: brandono66
4 Replies

5. Shell Programming and Scripting

Advanced error handling in shell scripts

Hi all I've got a question regarding error handling in shell scripts. My background is mainly object oriented programming languages, but for a year or so I've been doing more and more (bash) shell scripting (which I quite enjoy by the way). To handle errors in my scripts I... (3 Replies)
Discussion started by: script_man
3 Replies

6. Shell Programming and Scripting

handling null values in files

Hi , I have a script where i will remove header and trailer record and ftp to another server. I'm using the code: latestfilename=`ls filename_* | tail -1` echo "Latest filename = $latestfilename" sed '1d;$d' $latestfilename > a.ftpedfile I have an issue if input data is having null... (1 Reply)
Discussion started by: ammu
1 Replies

7. Shell Programming and Scripting

Null Character Handling

Hi All, I have a problem with Null values while reading line by line from a text file. I wrote a shell script to read set of file names from a text file line by line, and zipping the each individual file and copying those zip files into some separate directory, and removing the original file... (3 Replies)
Discussion started by: npk2210
3 Replies

8. UNIX for Dummies Questions & Answers

Handling Errors in Shell Scripts

I have a shell script, which calls a load script to load a database. How can i handle errors in Unix(similar to 'error level' in Batch scripts)? I am trying to use 'mailx' to send a Success/failure message based on the error level returned by the load script. I have already used an error log... (2 Replies)
Discussion started by: sarsani
2 Replies

9. Shell Programming and Scripting

Handling null input...

Ok, so when a user inputs nothing, simply pressing enter when prompted for a phone number, I get a "./addrbkfct.sh: test: argument expected" error message. I have the following function: addNumber(){ echo "Phone number: \c"; read number; echo $number; if ;... (2 Replies)
Discussion started by: DrRo183
2 Replies

10. UNIX for Advanced & Expert Users

Error Handling in Korn Shell scripts

Hi, I am using few ISQL statements to update and delete from a few tables in sybase, now i want to roll back the transaction when any of the statements fail.How i can i capture these errors in the shell scripts.Please advise. Thanks, Gopi (4 Replies)
Discussion started by: bhgopi
4 Replies
Login or Register to Ask a Question