Setting a variable in tcsh to a value that includes quotes and square brackets

832 Views Asked by At

an executable expects command-line parameters in the format:

-varname "[64]"

Need to wrap it as an environment variable so the executable can be launched by another tool, so I tried:

> setenv PARAM '-varname "[64]"'
> echo $PARAM
echo: No match.

I tried all kind of escapes but couldn't find how to enclose the original string into an environment variable.

Must mention that both the inner executable and the wrapper are inflexible in their expectations, e.g. the executable expects the variable as shown and the wrapper expects a string that it associates with an environment variable through 'setenv'.

Any hint?

Thanks!

1

There are 1 best solutions below

0
Chris Heithoff On

You are setting it correctly, but the problem is how the shell expands the value of $PARAM.

As you know, a star at the command line is expanded by the shell to all the files in the current directory.

> echo *

The result of shell expansion is subsequently used as the argument to echo.

There are additional wildcard/glob patterns allowed at the command line. Square brackets define character class. To echo all files containing either a 4 or a 6:

> echo *[46]*

To echo all files named exactly 4 or 6.

> echo [46]

In the above example, if no files are named exactly 4 or 6, then you'll get echo: No match.

Solution: use printenv
> setenv PARAM '-varname "[64]"'
> printenv PARAM
   -->  -varname "[64]"

Note that PARAM, not $PARAM is the argument to printenv. This avoid shell expansion of $PARAM.