Script(s) to Automate Tasks

I know that this has a bad title, but I'm not sure how to sum it up well.

(And I'm new to Linux in general, so please excuse any incorrect terminology :o)

Anyway, I'm trying to create a script that gets whatever folder you're in, and then does a command with that directory as an argument. I guess that it would be easier to show you than explain.

I want it to do a pwd command, and then just get that last folder (ie /home/alberte/study would translate into just study) and then put that on the end of a system command.

Now, I figured that I would be able to do this properly in bash, so I started out with this:

#!/bin/bash

pwd | sed 's_/_\
_g'

I would then pass this into a text file, look at the top two lines, and if there was text in the second line, it would delete the first line (eventually removing everything except the last folder). But then I realized that you couldn't do this with sed (or at least, I don't think it can). Talking with a friend, he directed me to perl, seeing as it would be easy to do text parsing, so heeding his words, I checked out perl.

Well, now, I can get perl to easily return the last word that was passed into it (ie "script.pl this is a test" would just print out "test"). So I figured that I could just call the perl script from the bash, and then I would be set. So, these are my scripts right now:

Bash

#!/bin/bash

pwd | sed 's_/_\ _g' | exec "/home/cfmc/study/perl.pl"

exit 0

Perl

#!/usr/bin/perl

$a = $#ARGV;

print "$ARGV[$a]\n"

Well, that really doesn't work. It looks like the Perl script isn't seeing this as arguments, but rather something else.

If any of you could point me in the right direction (even tutorials that feature this would be great), it would be very much appreciated. I've been working on this off and on for a few weeks, and I'd just like to get this done. Thanks for any help that you give in advance.

basename `pwd`

Alright, I didn't know that there was an easy way to get the folder that you're in, and not the entire path. Thanks a lot for the help. I appreciate it.

Here's my final script.

#!/bin/bash

x=$(basename `pwd`)

mentor $x.qpx -test

exit 0

Thanks again!