kittu
kittu

Reputation: 7018

Copy folder from current directory to parent folder in bash

I am trying to copy a folder(.husky) from current path to parent folder:

#!/bin/bash
# Get parent folder:
parent_folder=$(cd ../ && pwd)
# Trying to copy folder called `".husky"` into parent folder:
cp .husky $parent_folder/test1

But I am getting error saying:

fatal: not a git repository (or any of the parent directories): .git

Screenshot:

enter image description here

Upvotes: 0

Views: 386

Answers (1)

VonC
VonC

Reputation: 1328112

Regarding the parent folder, track first the current folder of your script, assuming .. is relative to where your script is:

DIR="$( cd "$( dirname "$(readlink "${BASH_SOURCE[0]}")" )" && pwd )"
parent_folder=$(cd "${DIR}" && pwd)
echo "parent_folder='${parent_folder}'"

Then add set -x in the first lines of your script to see where it triggers the "not a git repository" error message.


The OP kittu confirms in the comments:

Actually I had git alias setup previously where cp is alias cp='git commit -p', hence the git error.
Its working fine now.

Upvotes: 1

Related Questions