Home Linux piping data containing backticks
Reply: 1

Linux piping data containing backticks

svenema
1#
svenema Published in 2017-12-07 15:58:04Z

I'm piping output from one command into a second:

mpc listall | mpc add

mpc listall returns the following data (can output 1 or more lines):

Dare - 16 - I´ll Be Your King.mp3

When piping it into the next command, it seems that my shell (Ash on BusyBox) converts the ´ into an asterisk, as I get the error

error adding Dare - 16 - I*ll Be Your King.mp3: No such directory

Manually adding double quotes works! like this:

mpc add "Dare - 16 - I´ll Be Your King.mp3"

So, I tried adding those by sed and awk, but in those cases the backtick gets converted to an asterisk again:

mpc listall | sed 's/^/"/;s/$/"/'

returns:

"Dare - 16 - I*ll Be Your King.mp3"

So, question is, is there a way to pass backticks, or actually any character, as is, into another command without conversions?

By the way, obviously, it's quite bad to have this character in the file name in the first place, but I want my code to be robust and able to handle anything thrown at it.

svenema
2#
svenema Reply to 2017-12-08 09:51:32Z

Not a direct solution the problem, but a work-around (that's actually better, because it uses the API) in python using the python-mpd2 library:

myMpdClient = MPDClient() 
myMpdClient.connect("localhost", 6600)  # connect to localhost:6600
myMpdClient.findadd('base','directory-name')
myMpdClient.close()

I'll accept a working solution to the actual proposed problem, instead of this one, if someone posts a working solution.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.343908 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO