I have a question that may or may not have an answer in the form I am looking for, but any form will suffice.
I currently have a configuration file, in which I will use a shell command on that uses grep to find a specific line within the file, then I use sed to get all the text after a specific character. The remaining text is simply a file path that includes an environment variable. The output from the command returns something like this:
$LIGHTS_HOME/music/something.mp3
I then want to pipe that to mp3info to get usable meta data from the mp3 file. However, when I pipe that over to mp3info $LIGHTS_HOME doesn't expand to the actual file path it is correlated to. How can I expand it within one line? Is this even possible?
Here is my current command:
$ sudo grep -w "file_path =" /home/pi/lightshowpi/config/state.cfg |
sed 's/.*= //' | sed 's|'\$LIGHTS_HOME'| '/home/pi/lightshowpi'|' |
xargs mp3info -p "Now Playing: %t by %a" | xargs sudo python /home/pi/lightshowpi/tweet/tweet.py
What the command is doing(I have edited the line so that it is easier to read, in use it will need to be a single line (preferably, I am open to multi line if needed):
the first line uses grep to find the line 'file_path =', which returns the line 'file_path = $LIGHTS_HOME/music/songname.mp3'
Which is then piped to sed which parses the statement and returns all characters after the '=', which returns in this case '$LIGHTS_HOME/music/songname.mp3'
From there I use a second sed command to replace $LIGHTS_HOME with its variable value '/home/pi/lightshowpi/'
Ideally I would like to get rid of this second sed statement in favor of something that evaluates '$LIGHTS_HOME' to its value '/home/pi/lightshowpi/'
Which will then be used by mp3info to get the meta data of the file, which is formatted as a stdout which then is piped to xargs which prepares the meta stdout into a stdin format that the python script uses and tweets the value with a few other emoticon characters (which the python script does without an issue)
However, instead of using a second sed command of substituting $LIGHTS_HOME for /home/pi/lightshowpi I would rather have $LIGHTS_HOME expanded since on other installations this variable could be set somewhere other than the home directory.
I think I should note, that I am trying this whilst in terminal, I am not putting this inside a shell script. I am unsure if that changes things, I am still doing my best to learn shell, but I believe that this may change things based on the errors I keep getting.