The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - General (http://hintsforums.macworld.com/forumdisplay.php?f=16)
-   -   Shell Scripting help (http://hintsforums.macworld.com/showthread.php?t=73372)

cwtnospam 06-07-2007 12:05 PM

I think it would be easier to run the script with the folder opened and use the "set source_folder" line from post #18
If you drop the folder, it's location will change.

ataraxia 06-07-2007 02:46 PM

The "canonical" way to get just the last part of a file (or folder) name is to use "basename":
Code:

~ % basename /Users/ataraxia/Documents/resume.rtf
resume.rtf

You can also get it to remove a suffix for you:
Code:

~ % basename /Users/ataraxia/Documents/resume.rtf .rtf
resume

"dirname" does the opposite:
Code:

~ % dirname /Users/ataraxia/Documents/resume.rtf
/Users/ataraxia/Documents


Hal Itosis 06-07-2007 04:14 PM

Quote:

Originally Posted by honestpuck (Post 384064)
Oh, and in reply to the question of how to get just the filename portion of
the a path - use awk.

awk -F/ '{ print $(NF) }'

The above will work if you don't have a '/' at the end. If you do then replace (NF) with (NF - 1)

If I followed the above discussion correctly, there's also a specific
command for that (btw, why would a file's name end in /?):

basename "$a"

-HI-

Hal Itosis 06-08-2007 10:51 AM

Something weird is going on here:

When I wrote and submitted my above post at 4:14 PM [if indeed it was 4:14 PM?],
ataraxia's reply (designated 2:46 PM?) was not here!!!

In fact... my reply originally landed on page 1.

Strange.


All times are GMT -5. The time now is 05:41 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.