2013-02-19 50 views
2

我有例如下面的代碼:殼牌 - 創建追加內容的文本文件 - 使用貓

rm /etc/rc.local 
cat <<EOF >/etc/rc.local 
#!/bin/sh -e 
apt-get update && apt-get -y install git-core 
EOF 

有沒有一種方法而不是它的,所以我不需要刪除原來的rc.local中和做一個新的,但我可以使用幾乎相同的代碼,但追加這個內容到rc.local文件的底部,而不是重新創建它?

+2

使用>>而不是> – 2013-02-19 13:15:18

回答

3

試試這個:

cat <<EOF >>/etc/rc.local 

apt-get update && apt-get -y install git-core 
EOF 

或者乾脆:

echo 'apt-get update && apt-get -y install git-core' >> /etc/rc.local 
+0

我不應該需要這一行了,然後對不對? rm /etc/rc.local – Jimmy 2013-02-19 13:17:01

+0

已被刪除 – 2013-02-19 13:17:14

+1

@Jimmy無論如何你並不需要'rm':'>'完全替代了文件的內容,所以'rm'是多餘的。實際上'''表現得像'rm'後面跟着'>>' – syam 2013-02-19 14:16:32