2013-03-22 63 views
2

創建的文件一個新行/回車在我的bash腳本我有:如何把在由bash腳本

echo -e '#!/bin/sh /n GIT_WORK_TREE=/home/realopti/domains/$name git checkout -f' >> ~/domains/$name.git/hooks/post-receive 

這產生:

#!/bin/sh /n GIT_WORK_TREE=/home/realopti/domains/john git checkout -f 
在我的帖子收到文件

我想這個文件,看起來像:

#!/bin/sh 
GIT_WORK_TREE=/home/realopti/domains/john git checkout -f 

我怎樣才能做到這一點。

謝謝

比爾

回答

7

這應該是\n,不/n。您可能還想刪除它後面的空間,但沒關係。

+0

哎呀,對不起,你是對的 – user61629 2013-03-22 23:37:32

2

catecho這個更合適:

cat <<\EOF> ~/domains/$name.git/hooks/post-receive 
#!/bin/sh 
GIT_WORK_TREE=/home/realopti/domains/john git checkout -f 
EOF 

但對於這種特定情況下它可能會更好用的模板。把你想要的內容放在$HOME/template-dir/hooks/post-receive中,並將GIT_TEMPLATE_DIR=$HOME/template-dir設置在你創建你的git倉庫的shell的環境中。 (也就是說,在你的啓動文件中進行賦值。)