Get last line of shell output as a variable Get last line of shell output as a variable shell shell

Get last line of shell output as a variable


Put the tail inside the capturing parens.

OUTPUT=$(exif ... | tail -1)

You don't need the double quotes here. I'm guessing that youtried

OUTPUT="$(exif ...) | tail -1"


Probably an old post to be answering now, but try using the -n flag (see tail --help) and wrap the command output using ticks.

OUTPUT=`exif ... | tail -n 1`

(user464502's answer did not work for me as the tail command does not recognize the parameter "-1")