I've recently switched from bash to zsh, and now it seems I'm experiencing my first compatibility issue. I'm trying to write a shell script that checks exif date and time info in image and video files, and have a problem with this variable:

LINES="$(exiftool -CreationDate -CreateDate -DateTimeOriginal -ModifyDate -MediaCreateDate -MediaModifyDate -TrackCreateDate -TrackModifyDate "$filename" | awk -F ': ' '{print $2}' | sort -u | wc -l)"

When the piped commands above are entered directly in terminal for a given file, the output is 2 both in bash and zsh. However, when used in a variable as above, and then the command echo $LINES is entered, the output is 2 in bash, and 16 in zsh.

I wonder what difference zsh has here that I'm missing...

  • 5
    It may not be significant, but LINES is a special parameter in zsh (and a shell variable used internally in bash) - in general, it's best to avoid ALLCAPS names for your own shell variables. – steeldriver Feb 28 at 14:16
  • @steeldriver Thank you so much! I've just tried it naming the variable NR and it worked, and I was trying to figure out if LINES have a special meaning that I didn't know till now, and then I saw your reply. If you like you can enter this as an answer (as it really is) to earn points. ;-) – Sadi Feb 28 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.