
私はこう尋ねました質問SO で試してみましたが、あまり進みませんでした。これが私のスクリプトの現在のバージョンと、私がやりたいことです。デバッグとテストの提案が私の求めているものです。作業を-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
コメントを詳しく説明すると、末尾のバックスラッシュにより、3 つのln
コマンドが 1 行として扱われます。これは望ましくありません。必要なのは 3 つの異なる行です。したがって、3 行を echo すると、次のように解析されます。
$ 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
すべてのコマンドが 1 行にリストされていることがわかります。バックスラッシュを削除しても、この動作は発生しません。各コマンドは個別に処理されます。