Re: variable with "-" sign
From: c0ldbyte (c0ldbyte_at_comp.unix.shell)
Date: 04/02/05
- Next message: c0ldbyte: "Re: duplicating file structure to remote machine"
- Previous message: baumann_at_pan: "Re: what's difference among $(a) ${a} and $a"
- In reply to: Keith Thompson: "Re: variable with "-" sign"
- Next in thread: Keith Thompson: "Re: variable with "-" sign"
- Reply: Keith Thompson: "Re: variable with "-" sign"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 )
- Next message: c0ldbyte: "Re: duplicating file structure to remote machine"
- Previous message: baumann_at_pan: "Re: what's difference among $(a) ${a} and $a"
- In reply to: Keith Thompson: "Re: variable with "-" sign"
- Next in thread: Keith Thompson: "Re: variable with "-" sign"
- Reply: Keith Thompson: "Re: variable with "-" sign"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|