0
我需要在測試文件頂部插入:-name [email protected]$hostname
如何評估主機名?
如何評估hostname
? 我想:
sed -i '1s/^/-name [email protected]$hostname \n/' test_file
但結果是:
-name [email protected]$hostname
任何想法?
我需要在測試文件頂部插入:-name [email protected]$hostname
如何評估主機名?
如何評估hostname
? 我想:
sed -i '1s/^/-name [email protected]$hostname \n/' test_file
但結果是:
-name [email protected]$hostname
任何想法?
變量未用單引號擴展。嘗試雙引號:
sed -i "1s/^/-name [email protected]$hostname \n/" test_file
檢查也i
(插入)命令,它比s///
這些簡單的情況下,更容易。
sed -i "1i-name [email protected]$hostname" test_file
您需要首先分配一個值的變量:
hostname=$(hostname)
謝謝,但我得到了這樣的結果:'-name API @'沒事'後'@所以它已經評價''主機名作爲空白字符串.. – simo
您是否已將'$ hostname'設置爲任何值? – choroba
我發現它,我必須添加'()'作爲'$(主機名)'謝謝 – simo