problem w/ -z && -n switches in an if statment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem w/ -z && -n switches in an if statment
# 1  
Old 07-31-2002
problem w/ -z && -n switches in an if statment

When ever i run this if statement with the -n OR -z switches it always returns says positive and does "HAVE STUFF". BUT the file does not contain the word optimus in any form.

Code:
$echo this is mojo > test.file

$if [ -n `grep -i optimus test.file` ]; then
>echo HAVE STUFF
>else^Jecho NO STUFF
>fi
HAVE STUFF

$if [ -z `grep -i optimus test.file` ]; then
>echo HAVE STUFF
>else^Jecho NO STUFF
>fi
HAVE STUFF

basicly i am trying to test to see if optimus returns a postive response if it does do "HAVE STUFF" else do "NO STUFF".

the only way i have found around it is:

[ `grep -i optimus test.file|wc -l` -ge 1 ]; then........

anyone have any ideas.

SHELL: /bin/ksh
OS: sol8
platform: sparc

Last edited by Optimus_P; 07-31-2002 at 11:17 AM..
# 2  
Old 07-31-2002
never mind. im retarted.

when useing the -z and -n operants you must have a double bracket.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. Shell Programming and Scripting

Sort a the file & refine data column & row format

cat file1.txt field1 "user1": field2:"data-cde" field3:"data-pqr" field4:"data-mno" field1 "user1": field2:"data-dcb" field3:"data-mxz" field4:"data-zul" field1 "user2": field2:"data-cqz" field3:"data-xoq" field4:"data-pos" Now i need to have the date like below. i have just... (7 Replies)
Discussion started by: ckaramsetty
7 Replies

3. Shell Programming and Scripting

Problem with call of Java Programm & return code handling & output to several streams.

Hello Everybody, thanks in advance for spending some time in my problem. My problem is this: I want to call a java-Programm out of my shell skript, check if die return code is right, and split the output to the normal output and into a file. The following code doesn't work right, because in... (2 Replies)
Discussion started by: danifunny
2 Replies

4. Programming

IF && statement problem

Hello there, My first time on the forums, glad to be here :) I'm completely new to programming in PHP and I have a question which I hope someone could help me with. I am currently using this statement: if(($session == 2) && ($item == Dagger) && ($item2 == Dagger)){ ... (5 Replies)
Discussion started by: Hero
5 Replies

5. Shell Programming and Scripting

Replace & sign to &amp word

Hi, I have text file abc.txt. In this file, I have the following data. Input: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith & Mrs Smith Mr Smith& Mrs Smith Mr Smith &Mrs Smith Output: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith &amp Mrs Smith Mr Smith&amp... (4 Replies)
Discussion started by: naveed
4 Replies

6. Shell Programming and Scripting

replace & with & xml file

Hello All I have a xml file with many sets of records like this <mytag>mydata</mytag> <tag2>data&</tag2> also same file can be like this <mytag>mydata</mytag> <tag2>data&</tag2> <tag3>data2&amp;data3</tag3> Now i can grep & and replace with &amp; for whole file but it will replace all... (4 Replies)
Discussion started by: lokaish23
4 Replies

7. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

8. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

9. UNIX for Dummies Questions & Answers

Problem with xterm & tcsh & sourcing a script in a single command

Hi friends, I have a script that sets the env variable path based on different conditions. Now the new path variable setting should not done in the same terminal or same shell. Only a new terminal or new shell should have the new path env variable set. I am able to do this only as follows: >cd... (1 Reply)
Discussion started by: sowmya005
1 Replies

10. Linux

Having player problem && need your help.

My System is FC3, The following Players don't run well: 1).Helix Player couldn't play MP3 and *.wma files, 2).Totem is the same, 3)XMMS couldn't play .wma files. I am a newer of Linux,but I like Linux,just as you. Could you help me? Thank you! (1 Reply)
Discussion started by: letcorpmuv
1 Replies
Login or Register to Ask a Question