Re: I feel stupid -- determine the full path to a file

2007-12-11 Thread Andy Bradford
Thus said Andrew McNabb on Thu, 06 Dec 2007 15:57:03 CST: > argument_list="arg1 arg2 arg3" > some_program $argument_list > > Unfortunately, I could find no way to execute a program with a > variable length list of arguments. The following works, but requires a > fixed number of arguments:

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Charles Curley
On Thu, Dec 06, 2007 at 01:52:47PM -0700, Dave Smith wrote: > Shane Hathaway wrote: >> You must have lost the patch when your email client failed to check a >> return code. >> > > Nice. :) Return codes are for wimps. Checked exceptions are the way of the > future. ;) So where are the exception

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Dave Smith
Andrew McNabb wrote: If you don't like my example, I'm sure I could dig up some script that has strings that look like "\\""some string "\\"", where all of the backslashes only exist so that escaping will happen properly at some later point in the script. :( Agreed. Escaping and

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Andrew McNabb
On Thu, Dec 06, 2007 at 02:58:14PM -0700, Dave Smith wrote: > > xargs? So my example was bad. (of course, I wasn't thinking about xargs when I ran into that problem a while back). :) But my main point still stands. Namely, if you're trying to do something really complex, Bash tends to flake ou

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Dave Smith
Andrew McNabb wrote: In this case, you're lucky to have an obvious solution. Sometimes you just can't do it in Bash. I spent a long time once trying to run a command with a dynamically built argument list--something like this: argument_list="arg1 arg2 arg3" some_program $argument_list xar

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Andrew McNabb
On Thu, Dec 06, 2007 at 01:27:05PM -0700, Shane Hathaway wrote: > > I agree that bash is frequently easier, but its documentation is > scattered and IMHO bash is much more prone to bugs. Even the earlier > one-liner has a significant bug; it will fail if the path happens to > contain a space. In

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Michael L Torrie
Michael L Torrie wrote: > Levi Pearson wrote: >> >> (I realize that few, if any, of the readers of this list would >> seriously consider doing their scripting in Scheme, but you should at >> least follow that link for the 'Acknowledgements' section on that >> page, which is hilarious.) I will add

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Michael L Torrie
Levi Pearson wrote: > > You're right, python is the wrong language for shell scripting, but so > is sh/bash! What is the right one, you ask? Well, it's the Scheme > Shell (scsh), of course! See the manual at: > http://www.scsh.net/docu/html/man.html > > (I realize that few, if any, of the read

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Levi Pearson
Michael L Torrie <[EMAIL PROTECTED]> writes: > > You must love doing lots of popens and reading and writing to pipes in a > very manual fashion, then. If my problem involves scripting other > commands (like this one), then I submit python is the wrong language. > It the problem involves processing

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Dave Smith
Shane Hathaway wrote: You must have lost the patch when your email client failed to check a return code. Nice. :) Return codes are for wimps. Checked exceptions are the way of the future. ;) --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/o

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Shane Hathaway
Dave Smith wrote: > Shane Hathaway wrote: >> Didn't your mother teach you to check error codes? Your hard drive >> might spontaneously combust during the realpath() call, yet this program >> will happily print garbage and say it was miraculously successful anyway. > > Did you forget to attach you

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Dave Smith
Shane Hathaway wrote: Dave Smith wrote: int main( int argc, char **argv ) { if( argc != 2 ) { printf( "Usage: %s \n", argv[0] ); return 1; } char output[PATH_MAX]; realpath( argv[1], output ); printf( "%s\n", output ); return 0; } Didn't yo

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Nicholas Leippe
On Thursday 06 December 2007, Michael L Torrie wrote: > Nicholas Leippe wrote: > > realpath ../bar > > realpath doesn't appear to be a part of any stanard GNU coreutils I > have. Where does one obtain it? http://packages.debian.org/etch/realpath It's in portage, and installed by default on gento

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Shane Hathaway
Dave Smith wrote: > int main( int argc, char **argv ) > { > if( argc != 2 ) > { > printf( "Usage: %s \n", argv[0] ); > return 1; > } > > char output[PATH_MAX]; > realpath( argv[1], output ); > printf( "%s\n", output ); > > return 0; > } Didn't your mot

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Michael L Torrie
Shane Hathaway wrote: > I agree that bash is frequently easier, but its documentation is > scattered and IMHO bash is much more prone to bugs. Even the earlier > one-liner has a significant bug; it will fail if the path happens to > contain a space. Fortunately there's an obvious solution: Bash

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Peter McNabb
On Dec 6, 2007, at 12:59 PM, Michael L Torrie wrote: Andrew McNabb wrote: On Thu, Dec 06, 2007 at 12:47:32PM -0700, Shane Hathaway wrote: abspath=$(cd $(dirname $fn); pwd)/$(basename $fn) Okay. Yours it better than mine. :) Wow. Awesome. Bash is just one giant hack, isn't it. My solut

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Shane Hathaway
Michael L Torrie wrote: > Bash is just wonderful at putting existing tools together using > processes and pipes. While I could do everything in Python in this > case, bash is the more comfortable language for doing this kind of > thing. Especially since in my script, most of what I need to do is

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Michael L Torrie
Shane Hathaway wrote: > Michael L Torrie wrote: >> My solution, thanks to Byron clark is: >> >> abspath=$( readlink -f $fn ) >> >> readlink is part of the standard GNU coreutils. > > That's clearly the best answer, aside from Jonathan's sound > recommendation to write the script in Python instead.

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Dave Smith
Michael L Torrie wrote: I have a script that is passed a filename. This filename could be absolute, it could be relative. I need the script to be able to determine the pull path to this file. I've read lots of hacks for doing this that involve ls, find, and pwd, but none of them do what I need

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Shane Hathaway
Michael L Torrie wrote: > Andrew McNabb wrote: >> On Thu, Dec 06, 2007 at 12:47:32PM -0700, Shane Hathaway wrote: >>> abspath=$(cd $(dirname $fn); pwd)/$(basename $fn) >> Okay. Yours it better than mine. :) > > Wow. Awesome. Bash is just one giant hack, isn't it. > > My solution, thanks to Byr

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Michael L Torrie
Andrew McNabb wrote: > On Thu, Dec 06, 2007 at 12:47:32PM -0700, Shane Hathaway wrote: >> abspath=$(cd $(dirname $fn); pwd)/$(basename $fn) > > Okay. Yours it better than mine. :) Wow. Awesome. Bash is just one giant hack, isn't it. My solution, thanks to Byron clark is: abspath=$( readlink

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Andrew McNabb
On Thu, Dec 06, 2007 at 12:47:32PM -0700, Shane Hathaway wrote: > > abspath=$(cd $(dirname $fn); pwd)/$(basename $fn) Okay. Yours it better than mine. :) -- Andrew McNabb http://www.mcnabbs.org/andrew/ PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868 /* PLUG: http://plug.o

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Andrew McNabb
On Thu, Dec 06, 2007 at 10:49:27AM -0700, Michael L Torrie wrote: > > then I need foo to be able to get a path that's the real, reduced path, > without any dots in it. In other words, `pwd`/../bar is not going to > work. This is simple and dumb but seems pretty resilient. ##

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Shane Hathaway
Michael L Torrie wrote: > I have a script that is passed a filename. This filename could be > absolute, it could be relative. I need the script to be able to > determine the pull path to this file. I've read lots of hacks for doing > this that involve ls, find, and pwd, but none of them do what

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Mark Higbee
You can try using Perl here is a module I found on cpan Path::Class http://search.cpan.org/~kwilliams/Path-Class-0.16/lib/Path/Class.pm Or there is File::Spec Michael L Torrie wrote: Nicholas Leippe wrote: realpath ../bar realpath doesn't appear to be a part of any stanard GNU co

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Michael L Torrie
Michael L Torrie wrote: > I have a script that is passed a filename. This filename could be > absolute, it could be relative. I need the script to be able to > determine the pull path to this file. I've read lots of hacks for doing > this that involve ls, find, and pwd, but none of them do what

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Michael L Torrie
Nicholas Leippe wrote: > realpath ../bar realpath doesn't appear to be a part of any stanard GNU coreutils I have. Where does one obtain it? > > > /* > PLUG: http://plug.org, #utah on irc.freenode.net > Unsubscribe: http://plug.org/mailman/options/plug > Don't fear the penguin. > */ > -- M

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Michael L Torrie
Derek Carter wrote: > > Try dirname and basename nope. Doesn't work. $ dirname `pwd`/../foo/baz /my/current/path/../foo/baz I need it to return /my/current/foo/baz > > -- > Goozbach > > /* > PLUG: http://plug.org, #utah on irc.freenode.net > Unsubscribe: http://plug.org/mailman/options/pl

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Nicholas Leippe
realpath ../bar /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Derek Carter
Michael L Torrie wrote: I have a script that is passed a filename. This filename could be absolute, it could be relative. I need the script to be able to determine the pull path to this file. I've read lots of hacks for doing this that involve ls, find, and pwd, but none of them do what I need

Re: I feel stupid -- determine the full path to a file

2007-12-06 Thread Jonathan Ellis
On 12/6/07, Michael L Torrie <[EMAIL PROTECTED]> wrote: > If the script was invoked like this, > > foo ../bar > > then I need foo to be able to get a path that's the real, reduced path, > without any dots in it. In other words, `pwd`/../bar is not going to > work. > > Any tips? Write the script i

I feel stupid -- determine the full path to a file

2007-12-06 Thread Michael L Torrie
I have a script that is passed a filename. This filename could be absolute, it could be relative. I need the script to be able to determine the pull path to this file. I've read lots of hacks for doing this that involve ls, find, and pwd, but none of them do what I need. If the script was invoke