Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell - How to handle NULL parameters 1

Status
Not open for further replies.

srishan

MIS
Oct 29, 2002
55
0
0
US
Our Application calls a Shell --> Shell calls a PL/SQL.
Application passes the parameters to Shell and if some of them are NULL, the order of the parameters is getting screwed up.

Explanation: For example, if we have 5 parameters coming from Apps, if #3 is NULL, Shell only gets 4 parameters instead of 5(1, 2, 3, 4), as a result #3 and #4 are getting the values of #4 and #5, and #5 is completely gone.

I wish to get some hard coded value into #3 like 'Empty'.

Asking user to enter something like 'Empty' OR
automating this action behind screens are NOT options.

Issue needs to be handled in Shell, Any suggestions?

Thx,
Sri
 
How would the shell know which parameter is which? Does the format of the parameters differ? //Daniel
 
That is the problem.

Is there a way to sustain the NULL value in the parameter?
OR default the NULL to some value like 'Empty' OR 'Nothing'?

Apps must be calling the Shell like,

myShell.sh 100 200 " " 400 500

I added double quotes for identifying the missing parameter,
it should be sending atleast an empty space there. Is there way that we can tap it and make it some value like 'Empty'?

Thx,
Sri
 
no chances:
the caller of myshell.sh should handle this, don't
use spaces for empty params, but a placeholder like
the string 'empty'.
the shell cannot make the difference between
100 200 " " 300 400
and
100 " " 300 400 500 -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
If you can get the calling application to surround each of the parameters with "" exactly as you have in the posting above it will treat that parameter as an empty value, e.g.:

[tt]$ cat t
#!/bin/ksh

echo 1: $1
echo 2: $2
echo 3: $3
$ ./t one two three
1: one
2: two
3: three
$ ./t "one" "" "three"
1: one
2:
3: three
$[/tt]
Annihilannic.
 
All,

Thanks for your responses.

Issue has been resolved. I misunderstood the concept to start with. Application was sending the NULL parameter to Shell correctly. Shell was calling the .sql file as follows,

@test.sql $1 $2 $3

If $2 is NULL, parms are getting flipped at this point in Shell. All we did was, check each variable with,

`expr "$2" : '.*'` being equal to zero length, if it is, then put the string "Empty" in $2. Then call test.sql, which worked fine, FYI.

Thx,

SriDHAR
 
if in ksh:

: "${2}:=Empty" vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top