Checking for zip / compress to use - tips for improvement?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking for zip / compress to use - tips for improvement?
# 1  
Old 07-24-2012
Checking for zip / compress to use - tips for improvement?

Hi,

Just want to know if anyone can suggest if there is a "better" way of coding the if-then-else block below:


Code:
ZIP=""
if [[ -x "`which compress`" ]] ; then
   ZIP=`which compress`
   echo "ZIP program to use = ${ZIP}"
elif [[ -x "`which gzip`" ]] ; then
   ZIP=`which gzip`
   echo "ZIP program to use = ${ZIP}"
else
   echo "No ZIP binary to use ..."
fi

It is working the way I want it to, but just want to make it look a bit more "elegant" or "professional" may be :-) Smilie

The preference is to use compress but on some of the servers, compress does not exist but gzip does.

I believe the above code can be done in a shorthand format using : and ? but I can't remember how I did it before.

Any advise/tips much appreciated. Thanks in advance.
# 2  
Old 07-24-2012
What you have there is easy to read, maintainable code. Harder to read code is not more professional Smilie
# 3  
Old 07-24-2012
You could loop it easily enough.

Code:
for X in compress gzip zip
do
        [[ -x `which $X` ]] || continue
        break
done

if [[ -z "$X" ]]
then
        echo "No zip binary" >&2
        exit 1
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

2. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

3. HP-UX

HP-UNIX How to zip/compress files in a folder?

Environment: HP-Unix Operating System B.11.31 U ia64 I have a folder with around 2000 files. There are some files which sizes are more than 8 GB. I need to compress all the files in the folder into a single file, so that I can transfer the file. I tried with tar command, but the tar... (8 Replies)
Discussion started by: Siva SQL
8 Replies

4. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

5. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

6. UNIX for Dummies Questions & Answers

Issue: Compress in unix server and FTP to windows and open the compress file using Winzip

Hi All ! We have to compress a big data file in unix server and transfer it to windows and uncompress it using winzip in windows. I have used the utility ZIP like the below. zip -e <newfilename> df2_test_extract.dat but when I compress files greater than 4 gb using zip utility, it... (4 Replies)
Discussion started by: sakthifire
4 Replies

7. Shell Programming and Scripting

Any improvement possible in this script

Hi! Thank you for the help yesterday This is the finished product There is one more thing I would like to do to it but I’m not to certain On how to proceed I would like to log all output to a log in order to Be able to roll back This script is meant to be used in repairing a... (4 Replies)
Discussion started by: Ex-Capsa
4 Replies

8. UNIX Desktop Questions & Answers

file zip,rar,tar,compress,uncompress,unzip,unrar

i want know how to compress and uncompress file using unix, compress uncompress,zip,unzip,rar,unrar,how its work and more about this.:confused: (1 Reply)
Discussion started by: ismael xavier
1 Replies

9. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies

10. UNIX for Dummies Questions & Answers

Checking file size of zip file

I'm having a problem with a bash shell The shell is running through a list of zip filenames, copying the zip files to another location and adding a file to the zip files. All this is working great, however I also need to report on the size of the zip file and I keep getting wrong answers. ... (2 Replies)
Discussion started by: skwyer
2 Replies
Login or Register to Ask a Question