建立點文件腳本

建立點文件腳本

我問這個問題就這麼過去了,並沒有走多遠;這是我的腳本的當前版本以及我想要做的事情。我正在尋找調試和測試的建議。我可能會-fn在更多地處理這個問題時刪除它,因為它只是妨礙 - 必須將文件移動到臨時目錄中,然後再返回才能使任何內容正常工作。

#!/bin/bash

set -e

function makeLinks() {
    ln -sfn ~/Documents/Dotfiles/.bash_profile ~/.bash_profile\
    ln -sfn ~/Documents/Dotfiles/.gitconfig ~/.gitconfig\
    ln -sfn ~/Documents/Dotfiles/.gitignore_global ~/.gitignore_global
    source ~/.bash_profile;
    }

    read -rp "This may overwrite existing files. Are you sure? (y/n) " -n 1;
    echo "";
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        makeLinks
    fi;

答案1

擴展註解:結尾的反斜線導致三個ln指令被視為一行。你不要這樣。你想要三個不同的線。所以,當我回顯這裡的三行時,它們是如何解析的。

$ echo ln -sfn ~/Documents/Dotfiles/.bash_profile ~/.bash_profile\
>     ln -sfn ~/Documents/Dotfiles/.gitconfig ~/.gitconfig\
>     ln -sfn ~/Documents/Dotfiles/.gitignore_global ~/.gitignore_global
ln -sfn /cygdrive/d/home/prateek/Documents/Dotfiles/.bash_profile /cygdrive/d/home/prateek/.bash_profile ln -sfn /cygdrive/d/home/prateek/Documents/Dotfiles/.gitconfig /cygdrive/d/home/prateek/.gitconfig ln -sfn /cygdrive/d/home/prateek/Documents/Dotfiles/.gitignore_global /cygdrive/d/home/prateek/.gitignore_global

您可以看到所有命令的輸出echo都列在一行上。刪除反斜線不會導致這種行為。每個命令將被單獨處理。

相關內容