[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] How to protect > and interpret it later on? (w/o using e
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] How to protect > and interpret it later on? (w/o using eval) |
Date: |
Fri, 2 Dec 2011 09:43:12 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Fri, Dec 02, 2011 at 08:26:28AM -0600, Peng Yu wrote:
> When I call,
>
> execute.sh ls > /tmp/tmp.txt
>
> I want it actually to do
>
> echo "ls > /tmp/tmp.txt"
> ls > /tmp/tmp.txt
That is impossible. The redirection, being unquoted, is performed by the
shell where you are actually typing that. If you want the > symbol to
be passed to the script as (part of) an argument, then it must be quoted,
as in your second example:
> execute.sh "ls > /tmp/tmp.txt"
THAT will work. But why are you writing a script to read a shell command
and then execute it? There is already a program that reads shell commands
and then executes them. It's called bash.