2016-08-24 99 views
1

我想在從bash腳本中提問時重寫配置文件。這是我的代碼。如何在BASH中寫入多行字符串文件

function quality { 
    echo $1 > ~/.livestreamerrc 
    echo ".livestreamer was modified!" 
} 

best="stream-types=hls 
hls-segment-threads=4 
default-stream=best 
player=vlc --cache 5000" 

read -p "Set quality: " INPUT 
if [[ "$INPUT" == "!best" ]]; then 
    quality $best 
fi 

此代碼執行以下操作以.livestreamer文件雖然。

$cat ~/.livestreamerrc 
stream-types=hls 

爲什麼?

+1

是不是引號有問題?如果你有'var =「hello world 我在這裏」'然後'echo $ var',格式會丟失;相反,'echo「$ var」'效果很好。 – fedorqui

回答

1

將其更改爲

quality "$best" # double quotes to avoid word splitting 

然後

echo "$1" > ~/.livestreamerrc 

注意:值得一試的[ shellcheck ] documentation.Also,像INPUT完全大寫的變量是保留給系統。

相關問題