Problems using command where command contains single quote.

Problems using command where command contains single quote.

Post by I » Tue, 18 Jun 2002 11:33:04



Hi,

Following is my script, I am having problems getting it to execute
properly.  If I take the output of the echo and paste it and press
enter it works but putting the $command in between backticks yeilds:

Unknown command `'open'.

Here is my script:

#!/bin/bash

MIRROR="ftp.wayne.edu"
DIR="/linux/mandrake-devel/cooker"

COMMAND="lftp -c 'open $MIRROR; cd $DIR; mirror -e'"

echo $COMMAND
`$COMMAND`

Thanks in advance,

fly

 
 
 

Problems using command where command contains single quote.

Post by Andreas K?h? » Tue, 18 Jun 2002 11:59:42


Submitted by "IH" to comp.unix.shell:

Quote:> Hi,

> Following is my script, I am having problems getting it to execute
> properly.  If I take the output of the echo and paste it and press
> enter it works but putting the $command in between backticks yeilds:

> Unknown command `'open'.

> Here is my script:

> #!/bin/bash

> MIRROR="ftp.wayne.edu"
> DIR="/linux/mandrake-devel/cooker"

> COMMAND="lftp -c 'open $MIRROR; cd $DIR; mirror -e'"

> echo $COMMAND
> `$COMMAND`

> Thanks in advance,

> fly

As $COMMAND expands to the command that you want to execute, you
don't need to use backticks at all.   If you wanted to execute
the *output* of the command, then you would have had to use
backticks.

You could also try using eval.

--
Andreas K?h?ri
--------------------------------------------------------------
Stable, secure, clean, free:  www.netbsd.org

 
 
 

Problems using command where command contains single quote.

Post by IH » Wed, 19 Jun 2002 02:51:32


Thanks for the response.  I removed the backtics but received the same
result.

I also tried the following directly on the command line:

[cooker]# COMMAND="lftp -c 'open ftp.wayne.edu; cd
/pub/Mandrake-pub/Mandrake/Mandrake-devel/cooker/i586/; mirror -e'"
[cooker]# echo $COMMAND
lftp -c 'open ftp.wayne.edu; cd
/pub/Mandrake-pub/Mandrake/Mandrake-devel/cooker/i586/; mirror -e'
[cooker]# $COMMAND
Unknown command `'open'.

Pasting the output of the echo command into the shell, however, works fine.

I'll read about eval and see if it won't help me but in the meantime if
anyone else has any more suggestions they would be appreciated.

Thanks,

Quote:> As $COMMAND expands to the command that you want to execute, you
> don't need to use backticks at all.   If you wanted to execute
> the *output* of the command, then you would have had to use
> backticks.

> You could also try using eval.

 
 
 

Problems using command where command contains single quote.

Post by IH » Wed, 19 Jun 2002 03:50:05


I got it to work.  Using eval before my $COMMAND worked like a charm.

Thanks,

IH


Quote:> Thanks for the response.  I removed the backtics but received the same
> result.

> I also tried the following directly on the command line:

> [cooker]# COMMAND="lftp -c 'open ftp.wayne.edu; cd
> /pub/Mandrake-pub/Mandrake/Mandrake-devel/cooker/i586/; mirror -e'"
> [cooker]# echo $COMMAND
> lftp -c 'open ftp.wayne.edu; cd
> /pub/Mandrake-pub/Mandrake/Mandrake-devel/cooker/i586/; mirror -e'
> [cooker]# $COMMAND
> Unknown command `'open'.

> Pasting the output of the echo command into the shell, however, works
fine.

> I'll read about eval and see if it won't help me but in the meantime if
> anyone else has any more suggestions they would be appreciated.

> Thanks,

 
 
 

1. Problem in sed using double quotes and single quotes

I am trying to append a line using sed and get different results using
double quotes and single quotes.  I want to change the part being appended
to shell variables and hence, need to use double quotes.  This is what I
get:

$ cat foo
Doe, John:12.34:10
Smith, Mary:12.45:11
Bush, Jerry:13.10:9
$ sed '/Smith/a\
Doe, John:12.34:10
Smith, Mary:12.45:11
Bob, Billy:12.10:13
Bush, Jerry:13.10:9
$ sed "/Smith/a\
sed: Extra text at end of command: /Smith/aBob, Billy:12.10:13
$

Can someone please help?  I am using Korn shell on Solaris and have tried it
under Korn shell on HP/UX as well.  I get the same result.

Sanjiv

2. Cross Plstform File Sharing

3. replace single quote by escaped single quote

4. SSL with Websphere

5. Single quote in commands

6. ScSi Card?

7. Single quotes being added by shell upon command execution

8. Token Ring/ifconfig/MTU's

9. set command ignoring single/double quotes

10. problem with executing commands from within the shell using a command string.

11. Creating tcsh or csh alias containing both single-quotes and dollar

12. Using env variables in quoted sed command

13. diff among echo a>f; command<f; echo $a|command; command << $a; EOF