1

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?

5
  • man zsh might be a good place to start.
    – nohillside
    Mar 9, 2021 at 21:02
  • FYI -- The #/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}" Mar 9, 2021 at 22:20
  • You are right and the first line was not in the script on macmost.com, my mistake.
    – hans
    Mar 10, 2021 at 8:23
  • 1
    @user3439894 In zsh, double quoting is not necessary (except in a small number of cases that do not apply here). Even in sh, double quotes are not necessary in assignments (but they are in some very similar contexts, so they're a good habit). Apr 16, 2021 at 19:52
  • @Gilles 'SO- stop being evil', Thanks for the info! -- I typically use 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 to zsh I guess one of the days I'll start reading the The Z Shell Manual, which I have as PDF and HTML documents. Apr 16, 2021 at 20:12

1 Answer 1

1

Those "extensions" are actually modifiers. The syntax comes (is copied) from the Tenex C shell. More info here- https://web.cs.elte.hu/local/texinfo/zsh/zsh_23.html

1
  • Thank you. This question will not be known as the brightest. I (age: 70) had forgotten the term 'modifier' ... I found a simple blog after this: tlbx.app/blog/zshell-path-modifiers.
    – hans
    Mar 10, 2021 at 8:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .