You are not logged in.
Pages: 1
hi,
I am trying to write a little bash script for adding all songs with the same artist as the currently playing song. Here is what I already have:
artist=`mpc -f %artist% | head -n 1`
search=`mpc search artist "$artist" | sed 's|mp3|mp3"|g' | sed 's|ganze|"ganze|g'`
echo $search | mpc addthe sed commands are for enclosing all paths in the list by "
the point is that the last command doesn't work and I don't know why! if I type
echo $searchand copy the the output to the end of mpc add, mpd adds the songs to it's playlist. so my problem here is that mpc doesn't "eat" the content of the search-variable in the pipe. what am I doing wrong????
thx in advance
Offline
Have you thought of surrounding the $search variable in double quotes in the last line? If there are spaces involved in that variable, then you'll most likely need them.
- [ My Blog ] | [ AUR Packages ] | [ My deviantART ] | [ screenFetch ] | [ SilverIRC ] -
Offline
In theory, I guess it should work...
Maybe try this simpler one?
mpc search artist "$(mpc current -f %artist%)" | mpc addAlso, I tried when enclosing the paths in quotes (sed -r 's/(.*)/"\1"/' btw...) and mpc errored saying path not found. Perhaps he's smart enough to break on '\n' only and not care about spaces. I would try the above as-is and see how it goes.
Last edited by brisbin33 (2010-11-09 21:51:44)
//github/
Offline
Have you thought of surrounding the $search variable in double quotes in the last line? If there are spaces involved in that variable, then you'll most likely need them.
As far as I know, echo doesn't care about quotes unless you're trying to preserve whitespace at the beginning or end of the line.
# these are equivalent
var='my awesome variable'
echo $var
echo "$var"
# but these you need to be careful
var=' my awesome variable with whitespace '
echo $var
echo "$var"Last edited by brisbin33 (2010-11-09 22:01:26)
//github/
Offline
kittykatt wrote:Have you thought of surrounding the $search variable in double quotes in the last line? If there are spaces involved in that variable, then you'll most likely need them.
As far as I know, echo doesn't care about quotes unless you're trying to preserve whitespace at the beginning or end of the line.
# these are equivalent var='my awesome variable' echo $var echo "$var" # but these you need to be careful var=' my awesome variable with whitespace ' echo $var echo "$var"
Touche. It's been a long day for me, unfortunately. Starting to make slip-ups like that.
- [ My Blog ] | [ AUR Packages ] | [ My deviantART ] | [ screenFetch ] | [ SilverIRC ] -
Offline
hi,
thanks for your quick answers. finally the solution of brisbin33 worked very well. that's it how it should be: simple and short
. so I dropped the complex thing with lots of variables.
so thanks and good night
Offline
Pages: 1