[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to protect > and interpret it later on? (w/o using eval)
From: |
Pierre Gaston |
Subject: |
Re: How to protect > and interpret it later on? (w/o using eval) |
Date: |
Fri, 2 Dec 2011 09:00:10 +0200 |
On Fri, Dec 2, 2011 at 8:24 AM, Peng Yu <pengyu.ut@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-bash@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"
"$@"