2016-12-13 58 views
0

我正在編寫腳本來自動管理我的git電子郵件配置。在我的腳本中,我想輸出一條消息,通知用戶電子郵件配置已更改。我正在使用命令git config user.email來獲取新的電子郵件地址。但是,它將其打印到換行符。我想打印它到我的信息相同的行。在bash中刪除換行符

這是我現在有:

echo "Email not configured to Work in Work directory."; 
    git config user.email "[email protected]" 
    echo "Git email configuration has now been changed to " 
    git config user.email 
+1

你試過告訴'echo'不打印換行? –

回答

2

只需使用一個子shell替換這樣的:

echo "Email not configured to Work in Work directory."; 
git config user.email "[email protected]" 
echo "Git email configuration has now been changed to \"$(git config user.email)\"" 
1

help echo

選項:
-n不追加換行
-e啓用以下反斜線的解釋轉義
-E明確抑制反斜線的解釋轉義

+0

'-s'不是'bash'內置'echo'支持的選項。 – chepner

+1

因爲問題被標記爲'bash'我建議使用'help echo'來執行這個內建命令。 – Cyrus

+0

@chepner你說得對,但'-s'不是這裏問題的選項。 – Devon