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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

KSH script with a test on a NULL

Status
Not open for further replies.

kozlow

MIS
Mar 3, 2003
326
US
This works on my AIX systems but not my HP-UX

#!/bin/ksh
while read TBS
do
if ! [ $TBS ]
then
echo No Tablespace to process
continue
else
echo $TBS
fi
done < tbs

The tbs file contains sql output of all the tablespaces in my oracle database. The problem is that there is some blank lines in the file. I am tring to read the file, without processing any blank lines....

It will run if I remove the #!/bin/ksh

Error Received:
!: not found

Any ideas??????
 
Replace

if ! [ $TBS ]

with

if [ -z $TBS ]

;)


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
LKBrwnDBA is correct, but
- while already do the test,
it will break as soon TBS is empty
- the else (after a continue in 'if') is unused.
considere:
if [ xxx ]
then ... ; continue
fi
do-something

- so your code should be:
while read TBS
do echo $TBS
done < tbs



:) guggach
 
LKBrwnDBA....

Since the variable is Null, I recieve error:
./tst[4]: test: argument expected

guggach... The file I read has null lines in the begining and such.... I am not tring to continue at EOF....

Will Continue to look around....
 
Try using grep and quoting the variable...
Code:
#!/bin/ksh
grep . tbs | while read TBS
do
        if [ -z "$TBS" ]
        then
                 :
        fi
done

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top