I want to capture the name of an image file created with scrot. I can capture the filename like this:
$ image=$(scrot -s -e 'echo $n')
$ echo $image
2018-09-07-140419_185x76_scrot.png
I need to do that via su:
$ image=$(su someuser -c "scrot -s -e 'echo $n'")
However, image is empty.
I think this syntax is correct - this works:
$ greeting=$(su someuser -c "echo 'hello, world'")
$ echo $greeting
hello, world
I am not sure why this isn't working with scrot. I presume it something to do with how scrot launches its subshell - I guess it doesn't propagate its output?
scrotis not simply failing because an appropriateDISPLAYis not set in thesuenvironment and/orsomeuserdoesn't have authority to access it?scrotpart works just fine and the file is created successfully (did have to setDISPLAYetc for that to work however, so a good question to ask!)rootissuing thesuso no password is required. The user switch is needed to execute in the context of the user that the desktop belongs to otherwisescrotand other things I do later don't work.