1

I want to rewrite a configuration file when asked from a bash script. Here is my code.

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

This code does the following to .livestreamer file though.

$cat ~/.livestreamerrc
stream-types=hls

Why?

codeforester
  • 39,467
  • 16
  • 112
  • 140
minerals
  • 6,090
  • 17
  • 62
  • 107
  • 1
    isn't it a problem with quotes? If you have `var="hello world i am here"` and then `echo $var`, the format is lost; instead, `echo "$var"` works well. – fedorqui Aug 24 '16 at 14:13

1 Answers1

3

Change it to

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

and then

echo "$1" > ~/.livestreamerrc

Note : Worth checking the [ shellcheck ] documentation.Also, fully uppercase variables like INPUT are reserved for the system.

sjsam
  • 21,411
  • 5
  • 55
  • 102