Bash Scripting Problem

Garry T. Williams gtwilliams at gmail.com
Tue May 20 21:56:46 UTC 2008


On Tuesday 20 May 2008 13:44:09 Heitor Moraes wrote:
> On Tue, May 20, 2008 at 2:31 PM, Thomas Kappelmueller
> <tkappelmueller at thomas-krenn.com> wrote:
> > Example:
> > #!/bin/bash
> >
> > COMMAND='ls "test dir 1"'
> >
> > $COMMAND #have tried $($COMMAND), '$COMMAND'
> >
> > It always cuts it in half at the spaces.
> >
> > Error msg:
> > ls: cannot access "test: No such file or directory
> > ls: cannot access dir: No such file or directory
> > ls: cannot access 1": No such file or directory
> >
> > What am i not seeing?
>
> ` not '
> 
> COMMAND=`ls "test dir 1"`

I think the original poster meant that he had a directory (or file)
named "test dir 1".  If he does as you suggest, then the line

    $COMMAND

will no longer be a command, but the output of the command when the
original assignment was made.  That will result in an error.

The answer that suggested using

    eval $COMMAND

will do what I think the original poster intended.

-- 
Garry T. Williams --- +1 678 656-4579




More information about the fedora-list mailing list