Re: Need an AppleScript way to do this shell script
Re: Need an AppleScript way to do this shell script
- Subject: Re: Need an AppleScript way to do this shell script
- From: Graff <email@hidden>
- Date: Wed, 14 Jul 2004 21:39:28 -0400
Here is a handler that will do pretty much what you are asking:
----
on GetLast(theString)
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set theLast to ""
try
if (last text item of theString is "") then
set theLast to text item -2 of theString
else
set theLast to last text item of theString
end if
end try
set AppleScript's text item delimiters to oldDelims
return theLast
end GetLast
GetLast("/some/path/to/")
----
- Ken
On Jul 14, 2004, at 9:00 PM, Joe Klemmer wrote:
Man, this list is a little to high volume for me to keep up with so
could anyone answering this CC both the list and me directly?
I have a shell script that will take the full posix path of a file or
directory from stdin and print out only the very last part. i.e. If
given this -
$ namesrc.sh /usr/local/test/whatever/foo
it will print out -
foo
regardless of whether "foo" is a directory (folder) or a file.
Following is the bash script so you can see what it's doing. I will
put comments in appropriate places.
----------8<----------------8<--------------
#! /bin/bash
# This script will take a command line argument of a full unix path
# and print out the last node. If given a directory path it will
# print the last directory. If given a complete path to a file it
# will print out the file
# First, get the argument from the command line and put it into a
variable
#
here=$1;
# Use a built-in bash replacement facility to change all the / into
spaces
# and put that result into another variable
#
name=${here//\// };
# Print the variable with the space delimited path and pipe that to awk
# which will print out the value of the last field
#
echo $name | awk '{print $NF}'
----------8<----------------8<--------------
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.