problem with if -z string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers problem with if -z string
# 1  
Old 06-01-2006
problem with if -z string

someone please help me out here.

i am not a newbie. i just haven't posted on this board in years. i'm talking at least two and a half years. My last user name was TRUEST. i couldn't log into this name because i forgot my password and my aol email address has long been deleted.

anyway, i'm trying run this command to tell me if what is stored in a variable contains a number or not.

if [ -z $string ]

is that correct?

the actual script is this:

#!/bin/sh
result="`ps -ef | grep -v grep | grep loader | awk '{print $2}'`"
if [ "$result" -eq "0" ]
then
sleep 3
/apps/scripts/restart_feed.sh loader
echo "News_Loader Was Restarted On `date`"
echo " "
fi


the line with result. i'm trying to see if the variable result contains a number or an empty space. i'm running this on a Linux box. i know this stuff but i haven't scripted in so long i have forgotten a lot of things
Terrible
# 2  
Old 06-01-2006
i think you can use some thing like

#!/bin/sh
if [ ! -n "$(ps -ef|grep [l]oader)" ];then
sleep 3
/apps/scripts/restart_feed.sh loader
echo "News_Loader Was Restarted On `date`"
echo " "
else
echo "Loader is already running"
fi






Quote:
Originally Posted by Terrible
someone please help me out here.

i am not a newbie. i just haven't posted on this board in years. i'm talking at least two and a half years. My last user name was TRUEST. i couldn't log into this name because i forgot my password and my aol email address has long been deleted.

anyway, i'm trying run this command to tell me if what is stored in a variable contains a number or not.

if [ -z $string ]

is that correct?

the actual script is this:

#!/bin/sh
result="`ps -ef | grep -v grep | grep loader | awk '{print $2}'`"
if [ "$result" -eq "0" ]
then
sleep 3
/apps/scripts/restart_feed.sh loader
echo "News_Loader Was Restarted On `date`"
echo " "
fi


the line with result. i'm trying to see if the variable result contains a number or an empty space. i'm running this on a Linux box. i know this stuff but i haven't scripted in so long i have forgotten a lot of things
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a long string string problem for procmail

Hi everyone, I am working on fetchmail + procmail to filter mails and I am having problem with parsing a long line in the body of the email. Could anyone help me construct a reg exp for this string below. It needs to match exactly as this string. GetRyt... (4 Replies)
Discussion started by: cwiggler
4 Replies

2. Shell Programming and Scripting

Problem in comparing 2 files string by string

Hi Champs, I am a newbie to unix world, and I am trying to built a script which seems to be far tough to be done alone by me..... " I am having a raw csv file which contains around 50 fields..." From that file I have to grep 2 fields "A" and "B"....field "A" is to be aligned vertically... (11 Replies)
Discussion started by: jitendra.pat04
11 Replies

3. Shell Programming and Scripting

String comparison problem

Hi, can someone please help me!!! urgent! I have a strange issue here. I grep for 2 strings from a txt files and compare the string value. Though the string values are the same, they are compared as different values. Please help Case-1 -------- Here I grep for 2 different field values... (3 Replies)
Discussion started by: vani123
3 Replies

4. Shell Programming and Scripting

string to number problem

Hi actually what happen i have taken a value from database table and stored in variable and that value is 20100601 000000 but this value is stored as string value in database table so after storing this value in variable a when i did operation on this a variable like a=`expr ${a} +1` i m... (1 Reply)
Discussion started by: aishsimplesweet
1 Replies

5. Shell Programming and Scripting

String concate problem

Hello there, I am facing the following problem in string concate. I am returning a sql column value to a shell script variable . Now when I am trying to concate the variable with another string (string appears first) I am getting a space between the two concate. Example p is the shell... (2 Replies)
Discussion started by: Pratik4891
2 Replies

6. Shell Programming and Scripting

Runaway String Problem

Database.txt John:30:40 echo -n "New Title Please :" read NewTitle awk -F":" 'OFS = ":"{ $1 = "'$NewTitle'" ; print $0 } ' Database.txt> Database2.txt mv Database2.txt Database.txt what this does, is that when i input something into $NewTitle, it will update $1 which is "John" into... (3 Replies)
Discussion started by: gregarion
3 Replies

7. Programming

String and pointer problem

i am having a string like " X1 " ---> string lenght is 30 I have stored this to a chararry . ref so here ref = " X1 " now i trim the left space by my function . Si the string now becomes "X1 " ---> string lenght is 15... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

8. Shell Programming and Scripting

problem in replacing a string

Hi, I have a file with the path of the directory present somewhere in it.I have assigned the path of the directory name to a variable. I want to replace it with another string.The code i used was sed -e '/$variable/sbcd/' filename. since the path name includes slashes '/', my sed command... (9 Replies)
Discussion started by: ragavhere
9 Replies

9. Shell Programming and Scripting

String manipulation problem

Hi all I am new to this forum. Here is my problem. I have a log file created by syncsort which looks something like this. The Left and Right are Previous days data file and Current days data file respectively left source: /u01/filename1 right source: /u01/filename2 records left : 2334... (3 Replies)
Discussion started by: VASU15
3 Replies

10. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies
Login or Register to Ask a Question