• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Need an AppleScript way to do this shell script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Need an AppleScript way to do this shell script
      • From: Nigel Smith <email@hidden>
    • Re: Need an AppleScript way to do this shell script
      • From: Luca Nalin <email@hidden>
    • Re: Need an AppleScript way to do this shell script
      • From: Axel Luttgens <email@hidden>
    • Re: Need an AppleScript way to do this shell script
      • From: Graff <email@hidden>
  • Prev by Date: Record Access OSA by Ed email@hidden
  • Next by Date: How to monitor a process efficiently
  • Previous by thread: Re: Record Access OSA by Ed email@hidden
  • Next by thread: Re: Need an AppleScript way to do this shell script
  • Index(es):
    • Date
    • Thread