Created
August 15, 2016 08:00
-
-
Save shengyou/d1d9aa3e0c09b51c1f4e4de9122746bc to your computer and use it in GitHub Desktop.
在 bash 裡使用 sudo 將某字串/字段加到檔案的最後面
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# some string 是要加入的字串 | |
# /target/file/path 是要寫入的檔案 | |
# --append 是加到檔案最後,沒加的話就是覆蓋掉整個檔案 | |
# > /dev/null 是防止 tee 輸出 | |
echo 'some string' | sudo tee --append /target/file/path > /dev/null | |
# 也可以把一段文字加進去 | |
BLOCK=" | |
TEXT... | |
" | |
echo "$BLOCK" | sudo tee --append /target/file/path > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
參考的文章是這兩篇: