diff mbox

[1/2] tracetool: dtrace: handle in and next reserved words

Message ID 1332944776-4037-1-git-send-email-alevy@redhat.com
State New
Headers show

Commit Message

Alon Levy March 28, 2012, 2:26 p.m. UTC
Signed-off-by: Alon Levy <alevy@redhat.com>
---
 scripts/tracetool |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Lee Essen March 28, 2012, 4:26 p.m. UTC | #1
On 28 Mar 2012, at 15:26, Alon Levy <alevy@redhat.com> wrote:

> Signed-off-by: Alon Levy <alevy@redhat.com>
> ---
> scripts/tracetool |    6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/scripts/tracetool b/scripts/tracetool
> index 65bd0a1..e7cebf3 100755
> --- a/scripts/tracetool
> +++ b/scripts/tracetool
> @@ -494,9 +494,9 @@ EOF
>     i=1
>     for arg in $arglist
>     do
> -        # 'limit' is a reserved keyword
> -        if [ "$arg" = "limit" ]; then
> -          arg="_limit"
> +        # 'limit', 'in' and 'next' are reserved keywords
> +        if [ "$arg" = "limit" -o "$arg" = "in" -o "$arg" = "next" ]; then
> +          arg="_$arg"
>         fi
>         cat <<EOF
>   $arg = \$arg$i;
> -- 
> 1.7.9.3

Could we add 'self' to this list?

Lee.
Eric Blake March 28, 2012, 4:38 p.m. UTC | #2
On 03/28/2012 10:26 AM, Lee Essen wrote:

>> +        # 'limit', 'in' and 'next' are reserved keywords
>> +        if [ "$arg" = "limit" -o "$arg" = "in" -o "$arg" = "next" ]; then

[ ... -o ... ] is not portable.  POSIX says you must break it into:
[ ... ] || [ ... ]

or, more efficiently for this particular filtering, rewrite this as:

# munge reserved words
case $arg in
  limit | in | next ) arg=_$arg ;;
esac

> 
> Could we add 'self' to this list?

and using case makes it easier to add more reserved words:

case $arg in
  limit | in | next | self ) arg=_$arg ;;
esac
Peter Maydell March 28, 2012, 4:43 p.m. UTC | #3
2012/3/28 Alon Levy <alevy@redhat.com>:
> -        # 'limit' is a reserved keyword
> -        if [ "$arg" = "limit" ]; then
> -          arg="_limit"
> +        # 'limit', 'in' and 'next' are reserved keywords
> +        if [ "$arg" = "limit" -o "$arg" = "in" -o "$arg" = "next" ]; then
> +          arg="_$arg"
>         fi

The test -a and -o options are obsolete in POSIX shell scripts
(use "if [ foo ] && [ bar ]" instead).

In this case it would be neater to use 'case' anyway:
    case "$arg" in
        limit|in|next)
            arg="_$arg"
            ;;
    esac

-- PMM
diff mbox

Patch

diff --git a/scripts/tracetool b/scripts/tracetool
index 65bd0a1..e7cebf3 100755
--- a/scripts/tracetool
+++ b/scripts/tracetool
@@ -494,9 +494,9 @@  EOF
     i=1
     for arg in $arglist
     do
-        # 'limit' is a reserved keyword
-        if [ "$arg" = "limit" ]; then
-          arg="_limit"
+        # 'limit', 'in' and 'next' are reserved keywords
+        if [ "$arg" = "limit" -o "$arg" = "in" -o "$arg" = "next" ]; then
+          arg="_$arg"
         fi
         cat <<EOF
   $arg = \$arg$i;