Can't cd to a (passed) variable in bash script

by freebird54   Last Updated June 12, 2019 08:02 AM - source

I am using bash to get some information from audacious to conky for display (including album art). I get the path to the directory of the music file from audacious, then attempt to cd to that directory to find folder.jpg - if found, prepare for display. Unfortunately can't rely on 'well-formed' path names. None of them have a problem from terminal, but the evaluations that bash does... It chokes on doubled spaces ( ) ' / and probably others, although the current setup seems to handle - ok. Here's the relevant function:

    GetArt ()
        file_path=`audtool --current-song-tuple-data file-path` # get the path to the song
        file_path=$(eval echo "${file_path}")                   # pre-expand to full path
        cd "${file_path}"
        if [[ ! -e "folder.jpg" ]];                             # if no art work found
            cp ~/Work/vinyl.png /tmp/cover.png              # put in placeholder
            convert "${file_path}""/folder.jpg" -resize 120x120 /tmp/cover.png # ready for showing

Any ideas, or would getting out the wire brush and removing the rust from my 'C' compiler be easier?

I tried with double quotes, single quotes, backticks, and even a construct like:

code=$code \"\$filename\""

but nothing seems to work correctly as yet. Fortunately it fails 'pretty' because it just pops up the "can't find art" substitute pic instead, but sometimes things burp all over stderr until the next song - or album.

Related Questions

How do I delete all pop/rap music?

Updated April 06, 2018 00:02 AM

Script to restart conky

Updated December 29, 2017 19:02 PM

A script for copying random folders

Updated May 23, 2016 08:01 AM