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

Andrew McNabb amcnabb at mcnabbs.org
Thu Dec 6 14:57:03 MST 2007

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 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

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:

some_program $arg1 $arg2 $arg3

The original discussion was about whether to use a shell scripting
language or a general purpose language.  I've personally found that
shell scripting is incredibly convenient for simple tasks, but that
general purpose languages are usually more robust.  If I need to build a
simple pipeline, I'll use Bash.  But if I need to do something special
when a pipe breaks, I should use something like Python with the
Subprocess module.

Andrew McNabb
PGP Fingerprint: 8A17 B57C 6879 1863 DE55  8012 AB4D 6098 8826 6868

More information about the PLUG mailing list