On Fri, Dec 2, 2011 at 8:24 AM, Peng Yu <pengyu...@gmail.com> wrote:
> Hi,
>
> ~$ cat ../execute.sh
> #!/usr/bin/env bash
>
> echo ===="$@"
> "$@"
>
> $  ../execute.sh  ls >/tmp/tmp.txt
> $ cat /tmp/tmp.txt #I don't want "====ls" be in the file
> ====ls
> main.sh
>
> '>' will not work unless eval is used in execute.sh.
>
> $ ../execute.sh  ls '>' /tmp/tmp.txt
> ====ls > /tmp/tmp.txt
> ls: cannot access >: No such file or directory
> /tmp/tmp.txt
>
> How to make execute protect > and interpret it later on w/o using eval?
>

This really belongs to the new help-b...@gnu.org mailing list
* https://lists.gnu.org/mailman/listinfo/help-bash

The most simple is to redirect the output to standard error or the terminal:
echo ===="$@" >&2  # not that using set -x will give you this for free
echo ===="$@" > /dev/tty

Another possibilty is to pass the file name as an argument instead
file=$1
shitf
echo ===="$@"
exec > "$file"
"$@"

Reply via email to