Build a Build Script: Part 13

Regarding Part 13 of: Build a Build Script

  • Copy secretinfo.md but replace “42” with “XX”.
    One possible solution uses the sed command with option -i .
    sed -i 's/42/xx'
    The option -i (short for: –in-place) enables us to: directly edit our text within a file.

  • Zip the resulting /build directory.
    For this one I tried:
    zip build.zip -r /build
    The command line option -r adds files recursively, it should create a zip file for all the files inside the (sub-)directory /build. However, I’m currently getting an error message!

Further, I don’t know how to do the last two bullet point.
Thank you and look forward to seeing your inputs…

I believe your zip attempt will work if you move the option parameter to its proper location immediately following zip: zip -r build.zip /build

I’ll try to answer your other questions from this post, and previous posts when I have more time. I’m a little rusty with bash scripting, so I have to remember or re-learn to be of any use :wink:

Hopefully someone else better suited than me can chime in to assist you.

Happy coding!

2 Likes

Thank you, midlindner!

Although we’ve now managed to create our file build.zip;
however the progress was printing (stored 0%) and (deflated 10%), which does not look right?
Please see a screenshot below:
Build_a_Build_01

I found this:

When zip add a file, it will compress it if it makes sense.

If the file is big enough, zip will use the compression algorithm DEFLATE (and print “deflated” and the % gained with the compression).

For very small files the compression will make the result bigger (for example, if I manually deflate a file with 2 bytes, I will get 4 bytes) so zip decides to STORE them (no compression) : it prints “stored” and 0% because this “compression” didn’t change the size. zip will also STORE folders (no content).

You can easily play with the compression : zip -0 will STORE everything, zip -1 to zip -9 will change the compression level of DEFLATE and zip -Z bzip2 will change the compression method.

So, to answer to your question : the stored 0% is fine ! The file has been added but not compressed.

here: https://stackoverflow.com/questions/23484386/zip-stored-0-should-i-be-concerned

Most of those files are empty, so they don’t get compressed. To see if zip worked properly, you can hover over the “build” folder, click on the 3 dots, and delete the folder. Then in the bash console type:
$ unzip build.zip. This will unzip the zipped file into a new “build” folder. Compare the files to the files in your “source” folder, and you’ll see they are the same.

2 Likes

Thank you very much!
I just followed your delete/unzip idea, and it worked great!

2 Likes