Hi All,
I am writting a Sell Script, that takes Search String & File Name from the terminal and check for Null Status. If either is NULL then pgm should quit.
I wrote the following:
bash-3.2$ cat null_status_of_parameters.sh
#!/bin/sh
#WASS that takes Search String & File Name from the terminal and check for Null Status. If either is NULL then pgm should quit.
echo "Please Enter the Search String:"
read pat
if [ -Z $pat ]
then
echo "Pattern entered is Empty"
exit
else
echo "Please enter the File name:"
read file
if [ -Z $file ]
then
echo "File name not passed"
exit
else
echo "Following is the grepped output:"
grep $pat $file
fi
fi
bash-3.2$
Output:
bash-3.2$ ./null_status_of_parameters.sh
Please Enter the Search String:
Manish
./null_status_of_parameters.sh: line 8: [: -Z: unary operator expected
Please enter the File name:
text_file
./null_status_of_parameters.sh: line 15: [: -Z: unary operator expected
Following is the grepped output:
Hi all.... I am Manish, I am learning UNIX.
bash-3.2$
Could anyone please let me know why I am getting the error (highlighted in red above) even I am getting the desired output.
Many thanks in advance.
Thank you,
Manish