Need an AppleScript way to do this shell script
Need an AppleScript way to do this shell script
- Subject: Need an AppleScript way to do this shell script
- From: Joe Klemmer <email@hidden>
- Date: Wed, 14 Jul 2004 21:00:43 -0400
- Organization: Unix System/Network Administrator & Ad Hoc Programmer
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<--------------
--
Joe Klemmer <email@hidden>
Unix System/Network Administrator & Ad Hoc Programmer
_______________________________________________
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.