Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to interface with a system not managed by me that is doing some Unix command scripts and command to easily execute a job.

There is a variable substitution that doesn't work and I wonder if I can write a command to avoid the situation. There are many variables to set and I want the chance to enter an empty variable. The problem is that the system is not passing an empty variable and simply doesn't set the variable. I get

${option.VARIABLE}: bad substitution

I try to set something like that but isn't working.

if [ -z ${option.VARIABLE} ]; then option.VARIABLE=""; fi;

Any idea?

share|improve this question
    
Is ${option.VARIABLE} part of the original script, or part of your attempt to work around the empty variable condition? Are you perhaps thinking of ${option:VARIABLE} or ${option:-VARIABLE}? –  steeldriver Jun 24 at 16:32
3  
Is it possible that your script is meant to be interpreted by ksh93 and makes use of disciplines? –  Stéphane Chazelas Jun 24 at 16:53
1  
This would be much easier to answer if you could give us a minimal working example of the script that reproduces this error. –  terdon Jun 24 at 17:21
    
@steeldriver It's valid ksh93 syntax (see glenn's answer), and this looks like a plausible use case for it. –  Gilles Jun 24 at 23:47

2 Answers 2

up vote 3 down vote accepted

Dot is not a valid character in a variable name. The bash manual says (here)

name

A word consisting solely of letters, numbers, and underscores, and beginning with a letter or underscore. Names are used as shell variable and function names. Also referred to as an identifier.


However, my ksh93 man page says:

Definitions.

[...] An identifier is a sequence of letters, digits, or underscores start‐ ing with a letter or underscore. Identifiers are used as components of variable names. A vname is a sequence of one or more identifiers separated by a . and optionally preceded by a .. Vnames are used as function and variable names.

This part seems most relevant to your issue (emphasis mine):

Parameter Expansion.

[...] A variable is denoted by a vname. To create a variable whose vname contains a ., a variable whose vname consists of everything before the last . must already exist.

This feature exists only in ksh93, not in bash. If your script makes use of it, you need to run it under ksh93.

share|improve this answer
    
Actually, given the error message, the OP is running a ksh93 script in bash (or possibly mksh, but presumably bash given the tag). –  Gilles Jun 24 at 23:46

I think the "." in your variable name messes up your code.

Try removing that dot in your variable by e.g. renaming it from option.VARIABLE to optionVARIABLE.

share|improve this answer
    
Unfortunately I cannot modify that part, as the system is not under my control, and the "option." is inserted in any variable. If the variable is defined everything is working fine. This definitely a unix env, and I believe there must be a way to write a fix command for this –  Vargan Jun 24 at 15:23
    
is it inserted in front of every variable? you can't use ${VAR} then as far as I know. try without {} the curly brackets. Also you can empty your variable with VAR=;, so without double quotes ". –  polym Jun 24 at 15:40
    
Use the curly brackets is effectively working unless the variable is not filled with something, the problem is just how to set up this variable when is not set by the system –  Vargan Jun 24 at 15:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.