How Can I Get `Zip` to Use Relative Paths in a Script?
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...
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.
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 -