Alternative to && operator


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Alternative to && operator
# 1  
Old 07-05-2010
Alternative to && operator

"Both cases have to be true for the expression to evaluate "true". is that not so.
the following code does a read from a txt file, an then suppose to do the deletion ,but although the condition exists, its not performing the deletion
Code:
[ -z "${prt}" ] &&
   echo "\n\t Deleting printer ${prt} !!!"
   if ! $BIN/lpadmin -x ${prt} 2> /dev/null
   then
       echo " Failed to delete printer !!"
       continue
   fi
   echo "Printer ${prt} DELETED!"

Any insight to the above problem will be highly appreciated
# 2  
Old 07-05-2010
Code:
[ -z "${prt}" ] || {
   echo "\n\t Deleting printer ${prt} !!!"
   if ! $BIN/lpadmin -x ${prt} 2> /dev/null
   then
       echo " Failed to delete printer !!"
       continue
   fi
   echo "Printer ${prt} DELETED!"
}

# 3  
Old 07-06-2010
OK and if the condition does not exists, but i would like to still recreate it !
would it change the create statement?????
here is both the delete and create statements
Code:
#Delete or Create Printer
   [ -z "${prt}" ] || {
      echo "\n\t Deleting printer ${prt} !!!"
      if ! $BIN/lpadmin -x ${prt} 2> /dev/null
      then
          echo " Failed to delete printer !!"
          continue
      fi
      echo "Printer ${prt} DELETED!"
   }
      echo "Adding Printer $prt !!!!"
   if ! $BIN/lpadmin -p ${prt} -E -v ${drv}://${IP}:${port}
   then
       echo "Failed to add printers !!!"
       continue
   fi
   echo "\n\t Printer $prt:$drv://$IP:$port created"
done < diffs.txt

# 4  
Old 07-06-2010
Not tested but the following should work for you
Code:
    if [[ -z "${prt}" ]]; then
      echo "\n\t Deleting printer ${prt} !!!"
      if ! $BIN/lpadmin -x ${prt} 2> /dev/null
      then
          echo " Failed to delete printer !!"
          continue
      fi
      echo "Printer ${prt} DELETED!"
   else
      echo "Adding Printer $prt !!!!"
      if ! $BIN/lpadmin -p ${prt} -E -v ${drv}://${IP}:${port}
      then
          echo "Failed to add printers !!!"
          continue
      fi
      echo "\n\t Printer $prt:$drv://$IP:$port created"
    fi

# 5  
Old 07-07-2010
YES, YES....Smilie
Its now re-creating the printer because it does not exists.
Will it delete the printer if its exists and re-create it again??????
# 6  
Old 07-08-2010
I did the following!
  • Created a printer on my remote server.I ran the script on the local server and was happy that it created the printer on the local server just as, it was created on the remote server. IP's,name etc
  • I created another printer on my local server.I ran the script and expected the printer to be deleted.Instead it just recreated the printer which might not be required on the local sever.
  • Would the script require an adjustment or not?????Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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

Linux Platform - NDM Script - && Operator

Hi All, I have a requirement where i need to NDM 3 files from LINUX to Mainframe system & trigger a job in mainframe once the 3 files are transmitted successfully. I am getting an error message in the && operator (the code component where i am checking whether step 1/2/3 are completed). ... (2 Replies)
Discussion started by: dsfreddie
2 Replies

3. UNIX for Dummies Questions & Answers

Magic numbers '&' operator problem

Hello everyone, on the man page of "magic(5)" There is explanation "&, to specify that the value from the file must have set all of the bits that are set in the specified value" . My question is that what is the difference between '&' and equal operator '=' ? I tested it with file... (6 Replies)
Discussion started by: segmentation
6 Replies

4. Shell Programming and Scripting

How to write If statement using && and operator in Unix

Hi What is the syntax for if statement using && and || operator? if && ] || here its giving me an error to this if statement any suggestion?? (2 Replies)
Discussion started by: Avi
2 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 &amp; 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. UNIX for Dummies Questions & Answers

Search for & edit rows & columns in data file and pipe

Dear unix gurus, I have a data file with header information about a subject and also 3 columns of n rows of data on various items he owns. The data file looks something like this: adam peter blah blah blah blah blah blah car 01 30 200 02 31 400 03 57 121 .. .. .. .. .. .. n y... (8 Replies)
Discussion started by: tintin72
8 Replies

9. Shell Programming and Scripting

multiple conditions in if using && operator

VARIABLE="project" if && ] then echo "VARIABLE is not empty" fi this is not working what is wrong in the syntax?? (2 Replies)
Discussion started by: codeman007
2 Replies
Login or Register to Ask a Question