I try to parse a plain text config file A.conf
with the following content:
bitrate 500000
use_can 1
I want to use the number behind bitrate
to setup a CAN-interface with the appropriate bitrate.
Here is the corresponding part of my shell script:
bitrate="$(cat /home/pi/A.conf | grep 'bitrate' | awk '{print $2}')"
sudo /sbin/ip link set can0 up type can bitrate $bitrate
It works fine, if there is at least one empty space character after the number 500000
, but not if it is immediately followed by a newline.
In that case I get this error output:
" is wrong: invalid "bitrate" value
What is the reason for this behaviour and how can I fix it? I don't want to rely on the fact that each config file needs empty space characters before each new line.