How to run a .sh script to create a *.zip file? - bash

I try to write a shell script create_zip.sh to zip my desired folders as a .zip file.
The content of create_zip.sh is as following:
CODE_DIR='exercise_code/'
EXERCISE_ZIP_NAME='exercise_01.zip'
EXERCISE_DIR=$(pwd)
echo 'Zipping file '$EXERCISE_ZIP_NAME
zip -r $EXERCISE_ZIP_NAME $CODE_DIR
echo $EXERCISE_ZIP_NAME ' created successfully!!! '
But when I double-clicked on the file create_zip.sh, it just opened the Git Bash window and closed immediately. Then nothing happened! (No output message, no newly created *.zip)
How can I solve it? I am using Win10 and with Git Bash as default application to open *.sh file.
Any solution will be very appreciated.

You probably don't have zip installed in Git Bash.
Try the following steps:
Navigate to https://sourceforge.net/projects/gnuwin32/files/zip/3.0/
Download zip-3.0-bin.zip
In the zipped file, in the bin folder, find
the file zip.exe
Extract the file "zip.exe" to your "mingw64" bin
folder (for me: C:\Program Files\Git\mingw64\bin)
Navigate to https://sourceforge.net/projects/gnuwin32/files/bzip2/1.0.5/
Download bzip2-1.0.5-bin.zip
In the zipped file, in the bin folder, find the file bzip2.dll
Extract bzip2.dll to your "mingw64" bin folder (same folder - C:\Program Files\Git\mingw64\bin)

Related

Is it possible to zip multiple files without a parent directory on macOS?

I have two files that I would like to zip, a.txt and b.txt. I'd like to zip them into a file, called my.zip, in such a way that when my.zip is unzipped, the two files are placed into the current directory without being placed in a directory of any kind.
This is what I have tried so far, from within the directory that contains both files:
zip ../my.zip *
and
zip -j my.zip a.txt b.txt
Those commands create a file called my-zip that when unzipped, creates a directory called my-zip, with the two files inside of it. Instead, I'd like the files to be placed into the current directory, without being contained in a directory called my-zip.
EDIT:
To clarify, the way I am unzipping it is by double-clicking the zip file via Finder on OS X
How did you unzip the my.zip file? I just tried your commands and worked fine as expected. Commands that I ran,
$ zip my.zip a.txt b.txt
$ unzip my.zip
However, when I right click the file my.zip (in Nautilus file manager) and click 'Extract Here', it creates a folder called my and puts the contents in there.

unzip multiple zip files from within one biz zip file using Git Bash command line

I am new to this forum and new to working with Git Bash command line windows application. I have a task at hand that require to keep code in Git Hub. So start using Gitbash to transfer files to GitHub. I am having a problem to automate unzipping the code that i get from my Dev team. They send me a biz zip file with multiple zip files inside as a package / collection of zip files in a big zip file. e.g. the big zip file will contain: WebCode.zip SQL.zip SSIS.zip Reports.zip Release notes.docx
My Challenge is that, how can I unzip file: BigZipFIle.zip and its contents all in one shot: under GitBash command line prompt:
unzip -o BigZipFIle.zip
gives me folders:
WebCode.zip
SQL.zip
SSIS.zip
Reports.zip
what I actually want to do is to have a script that would:
unzip BigZipFIle.zip in the same folder c:\bigZipFile\
unzip all additional zipped folders:
go into each folder, pickup the unzipped files
transfer to GitHub respective folder, I have similar folder structure in github
I would really appreciate if some can help me create a script.
Thank you, Nad

Copy command in Mac Terminal fails with "No such file or directory"

This should be straightforward, but I'm getting weird results.
I have a folder with subfolders containing ~4000 files. I'm trying to copy just the files of a certain filetype to another folder, while preserving the subfolder hierarchy.
Command:
cp -R /Users/Steve/Desktop/Hardscapes/*.LOB /Users/Steve/Desktop/Temp
fails with the message:
"/Users/Steve/Desktop/Hardscapes/*.LOB: No such file or directory".
I created the command by typing cp -R then dragging the source folder to the terminal window, adding *.LOB after the /, and dragging the destination folder to the terminal window.
Troubleshooting:
replacing *.LOB with *.* gives the same error.
cp -R /Users/Steve/Desktop/Hardscapes/ /Users/Steve/Desktop/Temp copies the entire Hardscapes folder to Temp, with all its subfolders and files.
Thanks for your help and suggestions.
EDIT: The folder Hardscapes contains only other folders. If I run the command above using one of those folders as the source, the contents are copied faithfully. The folder Hardscapes itself contains no .LOB files - they're only in the subfolders.
So maybe that's the issue, cp can't find any files corresponding to Hardscapes/*.LOB? But I thought the -R switch was supposed to tell it to look through all the subfolders.
Next I put a file named Test.LOB in the Hardscapes folder. The command above copies only that file and none of the subfolders. It looks like the -R switch is not doing its job. Do I have the syntax right?
Try this:
rsync -a --prune-empty-dirs --include '*/' --include '*.LOB' --exclude '*' /Users/Steve/Desktop/Hardscapes/ /Users/Steve/Desktop/Temp
As you already mentioned, directory Hardscapes itself contains no .LOB files. That's why your mask /Users/Steve/Desktop/Hardscapes/*.LOB results in matching no files at all.

Where did I move my file to? (mv in git bash)

I'm using Git Bash on Windows and just moving my files around locally. Here's my folder path:
/e/Python/Python---CS-170/CS170_homework/
I tried to move my files from Python---CS-170 to the sub folder CS170_homework and it a bit of curiousity, I typed this:
mv Python---CS-170/CS170_homework /
Now all the content in the folder Python---CS-170 is moved somewhere. Can you tell me where the files are moved to? I know the place it went to is "/", but what does it mean?
Can you try running on the Git Bash these commands:
cygpath -w /
On my system I am getting output as:
C:\Program Files\Git\
You can navigate to the folder using explorer to find the files you are looking for.
Here is the documentation for the utility.

Zip all files in the directory by windows command

Zip all the files in the specific directory and I need to place the zip file in the same folder through windows command prompt.
I know command for unzip as below
"unzip SRCPath -d DestPath "
I am looking all the text files to compress and place the zip file in the same folder.

Resources