將一長串電子郵件地址放入多行宏變數中

將一長串電子郵件地址放入多行宏變數中

我有一個包含 20 個電子郵件地址的列表,我試圖將其作為 shell 腳本中的多行放入巨集變數中。在“寬”格式下,它工作正常並顯示為:

to_list="[email protected],[email protected],[email protected],[email protected]"

我想要如下所示的內容,但我在引號、逗號和換行符方面遇到了問題:

to_list="[email protected],[email protected], \
         .
         .
         .
         [email protected],[email protected]"

用法將是:

mail -s "Subject text here." $to_list < body_text.txt

根據語法,電子郵件應以逗號分隔,並且只有整個清單應用引號引起來,如寬格式所示。但是,我的測試只是將電子郵件發送到頂行。我很欣賞你的見解!

答案1

你想要這樣的東西:

to_list=(
        "[email protected],"
        "[email protected],"
        "[email protected],"
        "[email protected]"
        )
mail -s "Subject text here." "${to_list[@]}" < body_text.txt

那是使用一個數組,您試圖在其中創建一個字串。

相關內容