0

I would like to store command output in variable in bash but I don't know why with this command I can't...

The command alone :

su plex -s /bin/bash -c "export LD_LIBRARY_PATH='/usr/lib/plexmediaserver' && /usr/lib/plexmediaserver/Plex\ Media\ Scanner --list"

Return :

4: ANIMATIONS
3: CARTOONS
1: MOVIESHD
9: MUSIC
2: TVSHOWS

Here is what I am doing to store the result :

OUTPUT=$(su plex -c "export LD_LIBRARY_PATH='/usr/lib/plexmediaserver' && /usr/lib/plexmediaserver/Plex\ Media\ Scanner --list");
echo "$OUTPUT"

Unfortunately my var OUTPUT is empty.

I tried many variant (with "",``,..) without success.

Perhaps it's because the result come from another user (plex) ?

Can somebody help me please ?

ping
  • 1
  • try `read OUTPUT < <(su plex -s /bin/bash -c "export LD_LIBRARY_PATH='/usr/lib/plexmediaserver' && /usr/lib/plexmediaserver/Plex\ Media\ Scanner --list")` – zzxyz Oct 14 '17 at 00:59
  • https://stackoverflow.com/questions/2559076/how-do-i-redirect-output-to-a-variable-in-shell – zzxyz Oct 14 '17 at 01:03
  • 1
    The `$(cmd)` command expansion substitutes the **standard output** of `cmd`. Could your problem come from that? Are you sure your command outputs are sent to **standard output**? Isn't it **standard error**, instead? – Renaud Pacalet Oct 14 '17 at 05:54
  • @zzyxz Thanks for helping, the var OUTPUT is still empty with your code :( – ping Oct 14 '17 at 09:47
  • @RenaudPacalet I don't know which output is used, I tried to redirect it with 2>$1 but it doesn't work either – ping Oct 14 '17 at 09:50
  • @ping, it needs to be `2>&1`, not `2>$1` – Charles Duffy Oct 14 '17 at 12:38

0 Answers0