[NTLUG:Discuss] Shell script help

. Daniel xdesign at hotmail.com
Thu May 11 17:24:27 CDT 2006


That's perfect!  Exactly what I needed.  Now it's like:

if [ -f $PATHLIST ]
  then
    PATHLIST=`dirname $PATHLIST`
fi
cd $PATHLIST
....

I haven't tested it out yet, but I'm pretty sure that'll work nicely.  
Thanks!  



>Daniel
>Two Unix/Linux commands to explore
>     basename
>     dirname
>the first returns the filename, stripping off the path, and the second
>does the opposite.  Hope this helps
>Regards
>Fred James
>
>. Daniel wrote:
>
> >This should probably be real easy for someone with experience.  It'd be
> >pretty easy to write in C, so I'm a little embarassed that I find this 
so
> >challenging.  Here's the scenario:
> >
> >GNOME's Nautilus has user-scripts.  This, I thought, would be a terrific
> >vehicle for me to be able to create a "powertoy" (to borrow an 
expression
> >from Microsoft) that I once used frequently when I used Windows.  In 
this
> >case, the tool would let me right-click on a folder and "Launch Command
> >Prompt Here" where it would open a command shell window with the current
> >working directory was set to the location of the folder indicated.  So
> >that's what I want to do here.
> >
> >What I have to work with is the environment variable:
> >$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
> >
> >My script, as it is, kinda works.  It consists of two lines:
> >
> >#!/bin/sh
> >cd $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
> >gnome-terminal --geometry=132x25
> >
> >Since Nautilus does not determine whether the file indicated is a file 
or a
> >folder, the script is available always.  So I would like the behavior to
> >be:
> >
> >If it's a folder, change to that directory.  If it's a file, change to 
the
> >directory that file is in.
> >
> >In my mind, the logic would go something like:
> >
> >if filename is a file then
> >  trim filename back to the last folder name
> >endif
> >chgdir filename
> >
> >The trouble is that I can't figure out a way to trim the filename off 
the
> >end of full path list.
> >
> >So my request to any and all shell script wizards is "how do I trim a
> >filename off the end of a pathlist?"  e.g. make
> >"/home/username/pictures/dsc00054.jpg" into "/home/username/pictures"
> >
> >
> >
> >_______________________________________________
> >http://ntlug.pmichaud.com/mailman/listinfo/discuss
> >
> >
> >
> >
>
>_______________________________________________
>http://ntlug.pmichaud.com/mailman/listinfo/discuss





More information about the Discuss mailing list