![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to check for empty file in Perl? | deepakwins | UNIX for Dummies Questions & Answers | 1 | 03-04-2008 12:00 PM |
| Check for Empty Command Argument | Nysif Steve | UNIX for Dummies Questions & Answers | 6 | 09-19-2007 12:59 PM |
| check if file is empty | stolz | Shell Programming and Scripting | 6 | 07-24-2007 12:24 PM |
| How to check for null or empty string | doer | Shell Programming and Scripting | 5 | 07-23-2007 10:31 PM |
| How can I make the for command check to see if a file is empty before executing? | chrchcol | Shell Programming and Scripting | 3 | 07-29-2006 12:14 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello All,
I have written shell script whcih at the max 3 parameters. When only one commandline argument and other two command line arguments are passed as empty string like eg : archive ' ' ' ' Then i need to check whether the commandline arguments are empty or not. i have use -n and ! -z but both of them fail for the above scenario. Please let me know what is the alternative to solve this problem. Thanks in anticipation |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Look for the number of command line parameters. If 1, then consider the other 2 empty.
|
|
#3
|
|||
|
|||
|
Quote:
if it is one paramter then it is ok no need to check for empty strings. But if it is 3 parameters then i need to check whether the other two are emty since i know that there are 3 paramters. |
|
#4
|
||||
|
||||
|
See this.
Code:
[/tmp]$ cat try.ksh
#! /bin/ksh
if [[ -n "$1" ]] ; then
echo '$1'="[$1]"
else
echo '$1' is empty
fi
if [[ -n "$2" ]] ; then
echo '$2'="[$2]"
else
echo '$2' is empty
fi
if [[ -n "$2" ]] ; then
echo '$3'="[$3]"
else
echo '$3' is empty
fi
[/tmp]$ ./try.ksh
$1 is empty
$2 is empty
$3 is empty
[/tmp]$ ./try.ksh 12 " " " "
$1=[12]
$2=[ ]
$3=[ ]
[/tmp]$
|
|
#5
|
|||
|
|||
|
Quote:
Hello vino, thanks a lot for the quick reply. The above code works if send the parameters as sampleshellscript purge '' '' i.e when i send null parameters. but when i send parameters as sampleshellscript purge ' ' ' '; Then it does not work. I wonder why ?that is why i was looking for an alternative to -n. |
|
#6
|
||||
|
||||
|
Quote:
Code:
[/tmp]$ ./try.ksh 12 ' ' ' ' $1=[12] $2=[ ] $3=[ ] [/tmp]$ |
|
#7
|
|||
|
|||
|
Quote:
when we give empty paramters as sampleshellscript archive ' ' ' ' ; |
|||
| Google The UNIX and Linux Forums |