[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Commands run via xargs and bash returns different result
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] Commands run via xargs and bash returns different results |
Date: |
Tue, 4 Feb 2014 08:19:41 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Mon, Feb 03, 2014 at 10:52:32PM +0100, Richard Taubo wrote:
> By setting: my_path="{}? I was trying receive each of the paths
> handed over from mdfind via xargs, and then use this variable to
> create html list based output, e.g something like:
> "<li>$my_path</li>?
echo "<ul>"
while read -r path; do
echo "<li>$path</li>"
done < <(mdfind -whatever)
echo "</ul>"
And even that's fancier than you may need for this particular task.
(Writing it with the process substitution forces the loop to run in
the current shell, so that you can set variables inside the loop and
have them survive. The pipeline alternative does not permit that.)
xargs is obtuse, hard to use, and fraught with peril.
imadev:~$ echo "don't" | xargs echo
xargs: missing quote?: dont
A shell loop is far more flexible, and doesn't break on inputs that
contain spaces and quotes.