Re: variable with "-" sign

From: c0ldbyte (c0ldbyte_at_comp.unix.shell)
Date: 04/02/05


Date: Sat, 02 Apr 2005 04:14:34 GMT


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2005-04-01, Keith Thompson <kst-u@mib.org> wrote:
> " Lemieux" <jlemieux@ccs.carleton.ca> writes:
>> I'm running a wrapper environment script for an application.
>> Now the application requires that this variable
>> called UNIX-VERS be set. How do I specify
>> a variable name with special chars. in bash?
>> I know tcsh handles variable names with "-" .
>> So I tried to find a way to source or run the tcsh
>> script into the bash script. Hit a wall there too.
>
> Ick.
>
> That's an environment variable, right?
>
> The first thing I'd do is complain bitterly to the author of the
> application. It's a silly requirement.
>
> Yes, tcsh's "setenv" command allows you to set an environment variable
> with a '-' in its name:
>
> % setenv FOO-BAR foobar
>
> (and csh allows the same thing), but it doesn't let you read its value
> without ugly tricks:
>
> % echo $FOO-BAR
> FOO: Undefined variable.
> % echo ${FOO-BAR}
> Missing }.
> % echo ${'FOO-BAR'}
> Illegal variable name.
> % printenv | sed -n '/^FOO-BAR=/s///p'
> foobar
>
> I can't think of a way in bash to set such an environment variable so
> it appears in the bash process's own environment. (You can't source a
> tcsh script from bash, and running a tcsh script doesn't help since
> the environment doesn't propagate back to the parent process.)
>
> But you can use the "env" command to set the environment variable in
> a process:
>
> $ env FOO-BAR=foobar your-application
>
> since the "env" command happens to be less restrictive about variable
> names than bash is.
>
> If you really want the variable set in your bash script, you can
> invoke it from a tcsh or Perl wrapper, but it doesn't sound like
> that's necessary.
>

Standardized scripting that is not something that would pass any kind of
quiz with a proffessor. I do believe we have enough numbers, leters, and
underscores to use and come up with some better descriptive variables
than starting to use ones with hyphens. For those who dont know what a
hyphen is its the little key on your keyboard that looks like "-" that.
Now on to the real problem. Are you sure that the variable in question
isnt really $UNIX-$VERS instead of $UNIX-VERS and that possibly its just
a mistype in the file or something. Even if you should rewrite it if
there is variables being used that contain a hyphen in the actual variable
name and then create a patch and write the stupid author and send the
patch to him to make it easy on his life to fix the problem as hand
because he wrote a non POSIX conforming script.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (FreeBSD)
Comment: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xF7DF979F
Comment: Fingerprint = D1DC 0AA4 1C4E EAD4 24EB 7E77 B261 50BA F7DF 979F

iD8DBQFCThwpsmFQuvffl58RAunVAJ9QMjWkUUGtkVK8Wl8itF+tEypOBgCfe9ST
/6ZLVS+G/exXDPEKRmrRmIw=
=p4KD
-----END PGP SIGNATURE-----

-- 
( When in doubt, use brute force. -- Ken Thompson 1998 )


Relevant Pages

  • Re: variable with "-" sign
    ... > I'm running a wrapper environment script for an application. ... > script into the bash script. ... tcsh script from bash, and running a tcsh script doesn't help since ...
    (comp.unix.shell)
  • Re: getting intel fortran to work from cygwin command line?
    ... I am trying to get ifort to work from a bash script, ... Can someone who has this working post their bash environment ... Will is set environment variables in the current bash shell if I do ...
    (comp.lang.fortran)
  • RE: local admin account password
    ... environment, yes we may have these, but we still use the same methods. ... With regards to the script, this script is actually run from a secured ... The local passwords are secured both in a secure password ...
    (Focus-Microsoft)
  • Re: Script for your enjoyment
    ... Another environment specific aspect. ... I do not maintain any databases ... The script should do that for you. ... isn't anyone checking if a domain group exists before they add it". ...
    (microsoft.public.scripting.wsh)
  • RE: How can I get the logon script to be executed while having a custo
    ... I'm working on a replacement of msgina dll. ... I have also a lot of trouble to set environment vars like ... > requires the replacement of GINA by our own customized version, ... This login script is set by the system administrator at the ...
    (microsoft.public.win32.programmer.kernel)