Get last line of shell output as a variable

后端 未结 2 1990
走了就别回头了
走了就别回头了 2020-12-29 04:01

I am working on a shell script with exiftool to automatically change some exif tags on pictures contained in a certain folder and I would like to use the output to get a not

相关标签:
2条回答
  • 2020-12-29 04:45

    Put the tail inside the capturing parens.

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

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

    OUTPUT="$(exif ...) | tail -1"
    
    0 讨论(0)
  • 2020-12-29 05:01

    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")

    0 讨论(0)
提交回复
热议问题