shell脚本的ln -sfn -v出现意外行为

时间:2013-01-10 14:18:51

标签: bash shell sh

我有以下内容:

if [ $kernel == 'Darwin' ]; then
    $HOME="/Users/$user"
elif [ $kernel == 'Linux' ]; then
    $HOME="/home/$user"
fi

# Let the script know what the dotfiles dir is
dotfiles_dir="$HOME/dotfiles"

# Making symlinks to shell files, add yours as you need
echo 'Making symlinks to shell files'
ln -sfn -v $dotfiles_dir/shells/zsh $HOME/.zsh
ln -sfn -v $dotfiles_dir/shells/zsh/zshrc $HOME/.zshrc
ln -sfn -v $dotfiles_dir/shells/bash $HOME/.bash
ln -sfn -v $dotfiles_dir/shells/bash/bash_profile $HOME/.bash_profile
ln -sfn -v $dotfiles_dir/shells/bash/bashrc $HOME/.bashrc
ln -sfn -v $dotfiles_dir/shells/profile $HOME/.profile
echo "Done at [$time]...\n"

然而,这奇怪的输出:

[Other output here...]

Making symlinks shell files
/Users/eduan/.zsh -> /Users/eduan/dotfiles/shells/zsh
/Users/eduan/.zshrc -> /Users/eduan/dotfiles/shells/zsh/zshrc
/Users/eduan/.bash -> /Users/eduan/dotfiles/shells/bash
./bashrc -> /Users/eduan/dotfiles/shells/bash/bashrc
/Users/eduan/.profile -> /Users/eduan/dotfiles/shells/profile
Done at [08:15]...

[Other output here...]

有人可以告诉我为什么会出现这种意想不到的输出吗?其余的符号链接都是正确生成的,但是由于某种原因,Bash符号链接被搞砸了。

BTW,这是一个生成符号链接的大脚本。这只是其中的一部分,我把相关部分放在一起,这样你就不会感到困惑。 :)

编辑:

以下是该脚本最新版本的链接:https://github.com/Greduan/dotfiles/blob/master/scripts/make_symlinks.sh

2 个答案:

答案 0 :(得分:1)

符号链接命令的darwin版本缺少bashrc的目标,因此转到当前目录。

我不确定为什么脚本的那个位有两个版本?

此外,您只创建备份目录(如果已存在),这可能不对吗?

答案 1 :(得分:1)

这条线错了,不是吗。缺少目标目录。

ln -sfn -v $dotfiles_dir/shells/bash/bashrc