我正在尝试使用Bash脚本找到一种方法来重新定义存储库,我得到了这个,但它返回了一些我不知道如何修复它们的错误,例如:./bash.sh: line 3: $'\r': command not found
错误:
./bash.sh: line 3: $'\r': command not found
./bash.sh: line 6: $'\r': command not found
Updating Repo: /home/teste/ with url:
./bash.sh: line 8: $'\r': command not found
./bash.sh: line 16: syntax error near unexpected token `$'\r''
'/bash.sh: line 16: `(git fetch --all && git stash)
这是我得到的脚本
directory="/home/teste/" ## Where the server is located
original_dir="/root" ## Where we should back after the pull
cd $directory # switch to the git repo
repo_url=$(git config --get remote.origin.url)
echo "Updating Repo: $directory with url: $repo_url"
main_branch="master"
if [ "$repo_url" == "XXXXX" ]; then # if you have a repo where the primary branch isnt master
$main_branch="trunk"
fi
# update the repo, then stash any local changes
echo -e "\ncalling: git fetch --all && git stash"
(git fetch --all && git stash)
current_branch=$(git rev-parse --abbrev-ref HEAD)
# switch to master/trunk branch and rebase it, then switch back to original branch
if [ $current_branch != $main_branch ]; then
echo -e "\ncalling: git checkout $main_branch && git rebase && git checkout $current_branch"
(git checkout $main_branch && git rebase && git checkout $current_branch)
fi
# rebase the original branch and then stash pop back to original state
echo -e "\ncalling: git rebase && git stash pop on branch: $current_branch"
(git rebase && git stash pop )
#switch back to the starting directory
cd $original_dir
echo ""
答案 0 :(得分:1)
它是您的文件编码,而不是脚本本身 - 窗口回车与unix格式不同。如果您使用的是GUI编辑器,请将行结尾更改为' unix'或者“赢”'格式取决于您的操作系统。
还有一个名为dos2unix的工具可以针对文件运行,将行结尾转换为unix格式(反之亦然unix2dos)。
在.gitattributes配置中,您还可以设置所需的格式。这将确保您检查和提交的代码在将来得到相应的处理:
text eol=crlf # unix
OR
text eol=lf # windows
请参阅:https://help.github.com/articles/dealing-with-line-endings/
请参阅此页,了解为此猫设计皮肤的其他方法。'\r': command not found - .bashrc / .bash_profile