I am using a script on my iMac (Automator) that I found on macmost.com that contains the following lines:
#/bin/zsh
for f in "$@"
do
filedate=$(mdls $f | grep kMDItemContentCreationDate -m 1 | awk '{print $3, $4}');
filename=$f:t
filepath=$f:h
mv $filepath/{"$filename","$filedate $filename"}
done
It works fine but where can I find information about the extensions :t and :h?
man zsh
might be a good place to start.#/bin/zsh
shebang is missing!
, it should be#!/bin/zsh
and you should be putting double-quotes around the variables to prevent globbing and word splitting . E.g."$f"
,"$filepath"
,filename="${f:t}"
and:filename="${f:h}"
bash
and run my shell scripts thru ShellCheck and it often suggests double-quotes where it isn't absolutely necessary, however, I've just gotten into the habit of using double-quotes for most things except where I know it actually can be problematic. Since macOS has moved tozsh
I guess one of the days I'll start reading the The Z Shell Manual, which I have as PDF and HTML documents.