I've programmed in other languages but bash and unix in general are very new to me. I think a bash wizard might see an obvious solution, using the source command to read in a settings file - and assign values to my command string?
Ideally I'd like to create a command string from all the field/value settings in a file, by replacing their matches in a string.
My file will look something like:
settings.cfg
#!/bin/bash
#
# WiFi Settings
#
wifi_name=mywifiname
wifi_password=wifi-pwd
#
# Icecast Server Settings
#
icecast_server=icecast.domain.com
icecast_port=443
icecast_mount_url=/user/99999/show/0123456
icecast_show=RPi Demo Show
icecast_user=
icecast_password=icecast-pwd
#
# avconv setting for Raspbian Jessie Lite
# may not need if you're using a self compiled ffmpeg version
#
icecast_legacy=1
#
# Stream Settings - probably not safer to go higher unless great internet connection
#
stream_bitrate=128k
So if I used command:
source settings.cfg
There would be a variable named $stream_bitrate
that would have the value of "128k".
I could then use a string replace on stream_parameters= <stream_bitrate>
to make that look like stream_parameters= 128k
But I'm wondering if bash gurus can see a simple index based loop - or regular expression that might do the job for whatever parameters are loaded.
I can change my settings file to make it easier if needed. I've put "<>" around the replacement parameter locations - but those can be removed or modified if needed.
And it can be one command line string if needed.
EDIT: Move command line processing to second file
Would this work?
ProcessSettings.sh
#!/bin/bash
#
# Load in config file settings
source settings.cfg
# build command line string
start_cmd=avconv -re -i test.mp3 -c:a libmp3lame -ac 2 -ar 44100 -content_type audio/mpeg -b:a
stream_parameters="$stream_bitrate -f mp3 -ice_name "$icecast_show" -password "icecast_password" -legacy_icecast $icecast_legacy"
icecast_setup=icecast://$icecast_user:$icecast_password@$icecast_server:$icecast_port$icecast_mount_url
stream_cmd = "$start_cmd $stream_parameters $icecast_setup"
stream_parameters= $stream_bitrate
stream_parameters="$stream_bitrate -f mp3 -ice_name $icecast_show -password $icecast_password -legacy_icecast $icecast_legacy"