Discussion:
Bash passing a filename with a space into xargs?
(too old to reply)
Chris Roberts
2022-04-01 16:21:20 UTC
Permalink
How can I get this to recognize a filename with a space?
I am manipulating files in my script, but at the portion where I want to do a diff. I cannot get it to work.
Would someone out there know of a workaround? (Besides saying "don't have filenames with spaces in them). :-)

This is in bash:
uno="try this.txt"
dos=blah.pdf
echo "$uno" "$dos" | xargs -l bash -c 'echo uno:$0 dos:$1' | xargs
#OUT: uno:try dos:this

echo "$uno" "$dos" | xargs -l bash -c 'echo uno:$0 dos:$1'
#OUT: uno:try dos:this

echo uno:"$uno", dos:"$dos" #this works, but doesn't help in my script.
#OUT: uno:try this.txt, dos:blah.pdf

thanks,
crzzy1
Michael F. Stemper
2022-04-01 20:07:52 UTC
Permalink
Post by Chris Roberts
How can I get this to recognize a filename with a space?
I am manipulating files in my script, but at the portion where I want to do a diff. I cannot get it to work.
Would someone out there know of a workaround? (Besides saying "don't have filenames with spaces in them). :-)
uno="try this.txt"
dos=blah.pdf
echo "$uno" "$dos" | xargs -l bash -c 'echo uno:$0 dos:$1' | xargs
#OUT: uno:try dos:this
echo "$uno" "$dos" | xargs -l bash -c 'echo uno:$0 dos:$1'
#OUT: uno:try dos:this
echo uno:"$uno", dos:"$dos" #this works, but doesn't help in my script.
#OUT: uno:try this.txt, dos:blah.pdf
I can't quite tell what you're trying to do, but single quotes around
the definition of uno seems to help:


============================
#!/bin/bash

uno='try this.txt'
dos=blah.pdf

ls "$uno" "$dos"
============================
--
Michael F. Stemper
Psalm 94:3-6
Lewis
2022-04-02 18:56:41 UTC
Permalink
Post by Michael F. Stemper
Post by Chris Roberts
How can I get this to recognize a filename with a space?
I am manipulating files in my script, but at the portion where I want to do a diff. I cannot get it to work.
Would someone out there know of a workaround? (Besides saying "don't have filenames with spaces in them). :-)
uno="try this.txt"
dos=blah.pdf
echo "$uno" "$dos" | xargs -l bash -c 'echo uno:$0 dos:$1' | xargs
#OUT: uno:try dos:this
echo "$uno" "$dos" | xargs -l bash -c 'echo uno:$0 dos:$1'
#OUT: uno:try dos:this
echo uno:"$uno", dos:"$dos" #this works, but doesn't help in my script.
#OUT: uno:try this.txt, dos:blah.pdf
I can't quite tell what you're trying to do, but single quotes around
============================
#!/bin/bash
uno='try this.txt'
dos=blah.pdf
ls "$uno" "$dos"
============================
Also, IFS=$'\n' is an option.
--
It was all very well going about pure logic and how the universe was
ruled by logic and the harmony of numbers, but the plain fact was
that the disc was manifestly traversing space on the back of a
giant turtle and the gods had a habit of going round to atheists'
houses and smashing their windows.
Loading...