2

I am using a command,

gsettings2 monitor org.gnome.desktop.background picture-uri| cut -f2 -d "'"

This correctly gives uri for changed wallpapers. I want to pipe every such value to a function foo such that

function foo {
    echo "Value changed $1"
}

executes. How do I do it?

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
xyz
  • 3,349
  • 1
  • 23
  • 29

1 Answers1

3
gsettings2 ... | stdbuf -oL cut -f2 -d "'" | while read -r uri; do
    foo "$uri"
done

The while read loop calls foo for each URI it reads. The stdbuf -oL call is there to force cut to be line-buffered so its output is visible immediately.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • Hi, thanks for replying. I was trying this myself but this isn't working for some reason. Updated question. Please note that [gsettings monitor](https://developer.gnome.org/gio/stable/gsettings-tool.html) is itself an infinite loop. – xyz Oct 08 '14 at 21:19
  • What I don't understand is that if cut is working, why isn't this. – xyz Oct 08 '14 at 21:26
  • Does it help if you do `stdbuf -oL cut -f2 -d "'"`? The problem might be that `cut`'s output is fully buffered. If stdbuf helps let me know and I'll add it to my answer. – John Kugelman Oct 08 '14 at 22:19
  • Thanks, that's exactly what I needed. Phew, I never realized that `cut`might be the problem. – xyz Oct 09 '14 at 04:01