The output from exif looks like this:ExifMnoteCanon: Loading entry 0xcf27 ('(null)')...ExifMnoteCanon: Loading entry 0x3ca8 ('(null)')...ExifMnoteCanon: Loading entry 0xf88a ('(null)')...2013:08:22 18:01:16In my bash script, I store this in a variable:datetime=$(exif --debug --machine-readable --tag=DateTimeOriginal $file 2>&1)I want to extract the last line of this using bash parameter substitution. I thought this would work:datetime=${datetime##*\n}But the output is then:ull)')...2013:08:22 18:01:16Why doesn't this work and how can I fix it?
Extract last line of multiline string
bash;exif
Use ANSI C style escape sequence, $'\n' to indicate newline:% echo $datetime       ExifMnoteCanon: Loading entry 0xcf27 ('(null)')...ExifMnoteCanon: Loading entry 0x3ca8 ('(null)')...ExifMnoteCanon: Loading entry 0xf88a ('(null)')...2013:08:22 18:01:16% echo ${datetime##*\n}ull)')...2013:08:22 18:01:16% echo ${datetime##*$'\n'}2013:08:22 18:01:16As you can see otherwise \n is being treated as literal n.