Page 1 of 1

Return name of the file in a shell script, without the path?

PostPosted: Mon Sep 03, 2012 5:50 pm
by Jono
I'm using Hazel to run a shell script with this CLI tool to show the name of the file passed to it in a Notification Centre message. I use the following code:

MountainNotifier com.google.Chrome "Download Completed" "$1" ""

How would I get it to show just the name instead of the path to the file as well as the name in the Notification Centre message?

Re: Return name of the file in a shell script, without the p

PostPosted: Mon Sep 03, 2012 6:09 pm
by a_freyer
Jono wrote:I'm using Hazel to run a shell script with this CLI tool to show the name of the file passed to it in a Notification Centre message. I use the following code:

MountainNotifier com.google.Chrome "Download Completed" "$1" ""

How would I get it to show just the name instead of the path to the file as well as the name in the Notification Centre message?



Code: Select all
MountainNotifier com.google.Chrome "Download Completed" $(basename "$1") ""

Re: Return name of the file in a shell script, without the p

PostPosted: Mon Sep 03, 2012 6:34 pm
by Jono
That shows just the name, thanks!
I just had to wrap quotes around it as it was only showing the first word in the name.

Thanks again.