Compare Empty Variable

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Compare Empty Variable
# 1  
Old 06-10-2011
Compare Empty Variable

Hello All,

I am running the below code in my script. I want if jk is empty nothing should be appened to the file total_usage.

but apparently its not happening.Kindy let me know how to do it.



###################################
Code:
         jk=`ps auxf |grep -w $inputline|tr -s " "|cut -d " " -f1-|sort -nr -k5|grep -v root|grep -v grep`

         if [ -z "$jk"  ]
         then
        echo "Its OK"
#        sed -e "/$tool/d" -e '/^$/d' total_usage>>total_usage
#         sed -e "/$tool/d" total_usage>>total_usage
      else
            if [ $j -eq 0 ]
            then

                     echo -e "\n$tool\n">>total_usage
                          ps auxf |grep -w $inputline|tr -s " "|cut -d " " -f1-|sort -nr -k5|grep -v root|grep -v grep>>total_usage
                          j=`expr $j + 1`
              else
                    ps auxf |grep -w $inputline|tr -s " "|cut -d " " -f1-|sort -nr -k5|grep -v root|grep -v grep>>total_usage
   fi
fi

###################################

Regards

Ankit

Last edited by pludi; 06-10-2011 at 08:01 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue using empty variable in grep command

Hi, I'm writing a shell script and trying to grep a variable value, it works fine as long as there is a value in /tmp/list.out which is captured in $DSK but sometimes the file tends to be empty and that is where I'm having an issue while using grep which returns nothing. I know I can use something... (15 Replies)
Discussion started by: mbak
15 Replies

2. 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

3. Shell Programming and Scripting

How do I change a variable to something only if it's empty?

I feel like it is just a matter of using the $ operators correctly, but I can't seem to get it... hostname="network" ip="192.168.1.1" netmask="" variables=( $hostname $ip $netmask ) for var in ${variables} do if ; then $var="--" fi done echo... (7 Replies)
Discussion started by: etranman1
7 Replies

4. Shell Programming and Scripting

read variable from file show empty

Hi Folks, I am trying to read input from single line from a file and pass the read variable to one of the commands. However when I run the script it keeps the variable to be empty. I can however echo the variable ( but why it is empty when it goes to the command). Any help will be... (6 Replies)
Discussion started by: bhadu
6 Replies

5. Shell Programming and Scripting

Compare columns and rows with template, and fill empty slots.

Hi, I'm working on a script that will take the contents of a file, that is in a row and column format, and compare it to a arrangment file. Such that if there is any or all blanks in my content file, the blank will be filled with a flag and will retain the row and column configuration. Ex. ... (2 Replies)
Discussion started by: hizzle
2 Replies

6. Shell Programming and Scripting

How to check a variable for empty and a newline

I have a variable with a new line. I want to check this variable for empty or a new line Can anyone advise (4 Replies)
Discussion started by: Muthuraj K
4 Replies

7. Shell Programming and Scripting

How to check the variable is empty with spacing

How to check the variable is empty or not? aaa=" " how to check aaa variable is empty or just spacing? If only spacing inside.. it will asume it is empty. some are 6 spacing, or 8 spacing.. as long as variable is empty with spacing.. anyone can help me? (2 Replies)
Discussion started by: ryanW
2 Replies

8. Shell Programming and Scripting

How to compare that file name is empty?

i am finding some pattern this way.. fname=`grep -w "^$index" $HOME/UnixCw/backup/Path.txt` how to check that fname is empty i.e. if pattren doesnt found then i want to do other operations.... (7 Replies)
Discussion started by: AbhijitIT
7 Replies

9. UNIX for Dummies Questions & Answers

Trying to capture empty variable.

sorry for the title of this thread- I figured out how to capture empty variable by using- if then ........ This thread originally had two parts in it (one for capturing empty variable and the other to get the date time in 14 char format). Once I figured out the solution for the first part... (6 Replies)
Discussion started by: radhika
6 Replies

10. Shell Programming and Scripting

Empty Variable

I am trying to assign list of files that created that day to a variable 'filename' filename=`ls -ltr |grep "Mar 6" | awk '{print$9}'` If there are no files created that day, my script just hangs, i need help with some login here. i am also trying to figure out a way to look for files that... (3 Replies)
Discussion started by: gundu
3 Replies
Login or Register to Ask a Question