Glam Prestige Journal

Bright entertainment trends with youth appeal.

Normally I use zip command with:

zip -r my_arch.zip my_folder

Now I am using zip in an bash script in this way:

#!/bin/bash
OUT=$1
NAME=$2
zip -r -q $OUT/$NAME $OUT/$NAME

I call the script with:

./mySrcipt /home/edevise/foo myFiles

Opening the resulting zip file shows, that the full path was used to zip the folder foo. E.g. opening the zip file shows the home folder and I need to navigate through all subsequent folders until I see my folder foo.

How to adapt the script to zip the folder foo, only?

PS: Please don't wonder about the sense of the script. It is just an example to show the problem.

4

1 Answer

If you want only relative paths in the zip file, you should add a cd command to your script:

#!/bin/bash
OUT="$1"
NAME="$2"
cd "$OUT"
zip -r -q "$NAME" "$NAME"
cd -
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy