将文件夹从当前目录复制到 bash 中的父文件夹

Copy folder from current directory to parent folder in bash

我正在尝试将文件夹 (.husky) 从当前路径复制到父文件夹:

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

但我收到错误提示:

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

截图:

关于父文件夹,首先跟踪脚本的当前文件夹,假设 .. 相对于脚本所在的位置:

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

然后在脚本的第一行添加 set -x 以查看触发“not a git repository”错误消息的位置。


OP kittu confirms :

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