0

To set the stage, I have this 2 equivalent and working 'xargs' composed commands, in this sample echo scenario:

// ok
$ echo org.cinnamon.desktop.keybindings.wm move-to-workspace-5 | xargs echo
org.cinnamon.desktop.keybindings.wm move-to-workspace-5

// ok
$ echo org.cinnamon.desktop.keybindings.wm move-to-workspace-5 | xargs -I '{}' echo '{}'
org.cinnamon.desktop.keybindings.wm move-to-workspace-5

Now, when I replace the 'echo' command with 'gsettings get' the second case fails:

// ok
$ echo org.cinnamon.desktop.keybindings.wm move-to-workspace-5 | xargs gsettings get
['<Alt>F4']

// fails
$ echo org.cinnamon.desktop.keybindings.wm move-to-workspace-5 | xargs -I '{}' gsettings get '{}'
Usage:
  gsettings [--schemadir SCHEMADIR] get SCHEMA[:PATH] KEY

  Get the value of KEY

 Arguments:
   SCHEMADIR A directory to search for additional schemas
   SCHEMA    The name of the schema
   PATH      The path, for relocatable schemas
   KEY       The key within the schema

What is going on and how can I get more visibility in the issue?

  • also see my ranting about xargs -I here – mosvy Nov 6 '18 at 21:54
  • -I {} gives me flashbacks to the horror that is find's horrid stuff. I have found that -I_ or -IXXX are easier to follow. – Aaron D. Marasco Nov 6 '18 at 22:34
1

The -I {} options of xargs will cause it to pass a whole line from the input as a single argument.

This is what the manpage of xargs(1) says:

-I replace-str

Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate input items; instead the separator is the newline character. Implies -x and -L 1.

You can easily see the difference by using an arguments printing script instead of gsettings:

$ cat /tmp/a
#! /bin/sh
echo -n "$0"; for a; do echo -n " {$a}"; done; echo
$ chmod 755 /tmp/a

$ echo foo bar | xargs /tmp/a
/tmp/a {foo} {bar}

$ echo foo bar | xargs -I '{}' /tmp/a '{}'
/tmp/a {foo bar}

What to do next depends on what you want to achieve with those commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.