繁体   English   中英

如何在bash脚本创建的文件中放入新的行/回车符

[英]how to put a new line/carriage return in file created by a bash script

在我的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

我怎样才能实现这一目标。

谢谢,

法案

那应该是\\n ,而不是/n 您可能还想删除它后面的空格,但这没关系。

对于这个来说, 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存储库的shell环境中设置GIT_TEMPLATE_DIR=$HOME/template-dir (也就是说,在启动文件中进行分配。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM