Sponsored Content
Full Discussion: Check for empty string
Top Forums Shell Programming and Scripting Check for empty string Post 302161197 by rahman_riyaz on Thursday 24th of January 2008 12:35:15 AM
Old 01-24-2008
Quote:
Originally Posted by vino
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]$


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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check for null or empty string

Hi, I need to check for value not equal (<>) to 21 and not equal empty or null values. Please modify this script if then echo "$VALUE,$BSC_NAME,$BSC_ID" > $OUT_FILE/power_up.out end if TQ (5 Replies)
Discussion started by: doer
5 Replies

2. UNIX for Dummies Questions & Answers

How to check if a file is empty?

Hi Masters..... I have problem !!! I need to check number of records in a file and if it is zero or file is empty i need to do some task. if ; then echo "File s empty" else echo "Not empty" fi so how to check this condition. I used wc -l < filename.txt => 1 for zero records same result... (1 Reply)
Discussion started by: shreekrishnagd
1 Replies

3. Shell Programming and Scripting

check whether the directory is empty or not

I have the list of users in user.log, under each user folder there is sub1 folder is there. i want to check whether sub1 is empty or not, if it is empty i have to skip that user user folder and iterate next user folders. i have the sample code,its not giving not proper results. while read line... (8 Replies)
Discussion started by: KiranKumarKarre
8 Replies

4. Shell Programming and Scripting

check empty directory !!!

I need to check if a directory is empty using an if condition in the pseudocode below if ; then else although i looked at a few forums on this topic, I left feeling a little unclear and i could not use the command successfully what can i substitute in the if conditon above,... (2 Replies)
Discussion started by: allah_waris45
2 Replies

5. UNIX for Dummies Questions & Answers

Check to see if string var is empty

i have a veriable set var1 set var2 = abcd how can i check if var 1 is empty and if var 2 is not empty ??? (2 Replies)
Discussion started by: nirnir26
2 Replies

6. Shell Programming and Scripting

Check if the string is empty

I am reading from a file and executing the jobs with/without parameters as the job requires. File job1 R job2 job3 Y 123 if then <job>.ksh else <job>.ksh $params fi This works fine if the line read from the file has parameters it executes like job1.ksh R But for... (2 Replies)
Discussion started by: nw2unx123
2 Replies

7. Shell Programming and Scripting

How to check whether a variable is empty or contains some value?

hi, i want to check whether a a variable contains some value or is empty in a shell script. so if the variable contains some value i want to do some job and if the variable doesnt contain any value then i need to skip that job. here is a sample script read_filenames.sh contains ... (5 Replies)
Discussion started by: Little
5 Replies

8. Shell Programming and Scripting

Empty file check

Hi gurus , I have two files and i want to perform different action based on the condition if both or either is empty If then Do something elif then do something elif then do something else do something fi I have tried the below bt its not... (4 Replies)
Discussion started by: r_t_1601
4 Replies

9. Shell Programming and Scripting

How to check empty string in an XML tag?

I have an XML tag <abc> which is empty as <abc></abc>.If the the tag is empty I want to flag the file as bad. Please help. Thanks (3 Replies)
Discussion started by: aneeta13
3 Replies

10. Shell Programming and Scripting

Cant check empty string

Hello So i have that script collection, in which i have a single script to create a configuration file. In there, i have multiple occourences of something like this: prj_title=$(tui-read "What is the TITLE? ($prj_name):") ] && prj_title="${prj_name/_/ }" They all work as expected, if... (5 Replies)
Discussion started by: sea
5 Replies
getopt(1)						      General Commands Manual							 getopt(1)

NAME
getopt - parse command options SYNOPSIS
optstring args DESCRIPTION
is used to break up options in command lines for easy parsing by shell procedures and to check for legal options. optstring is a string of recognized option letters (see getopt(3C)). If a letter is followed by a colon, the option is expected to have an argument, which may or may not be separated from it by whitespace. The positional parameters ...) of the shell are reset so that each option is preceded by a and is in its own positional parameter; each option argument is also parsed into its own positional parameter. recognizes two hyphens to delimit the end of the options. If absent, places at the end of the options. The most common use of is in the shell's command (see the example below) where converts the command line to a more easily parsed form. writes the modified command line to the standard output. EXTERNAL INFLUENCES
Environment Variables determines the language in which messages are displayed. If is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty vari- able. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single-byte and multibyte character code sets are supported. DIAGNOSTICS
prints an error message on the standard error when it encounters an option letter that is not included in optstring. EXAMPLES
The following code fragment processes the arguments for a command that can take the options or and the option which requires an argument: This code accepts any of the following as equivalent: WARNINGS
option arguments must not be null strings nor contain embedded blanks. SEE ALSO
getopts(1), sh(1), getopt(3C). getopt(1)
All times are GMT -4. The time now is 05:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy