Reputation: 9046
I want to use a variable with this name: topMiddleOligocenetoUpperEocene?
how can I do it in a shell script (i.e., using the question mark)? I tried:
{topMiddleOligocenetoUpperEocene?}="something"
but it's not understood in my shell script (myfile.sh using in the first row #!/bin/sh).
Any hint will be appreciated, thanks in advance.
Upvotes: 2
Views: 4247
Reputation: 785481
No you cannot use ?
in unix shell variable names. In fact many other special characters such as period, comma, ?
aren't allowed.
This is the regex for shell variable names:
[a-zA-Z_][a-zA-Z0-9_]*
Upvotes: 4
Reputation: 10039
? cannot be part of a variable name like : % = and lot more special meaning for shell. In this case it will try to find a file starting with your variable name and 1 character (any character). Unless you have one that can be executed by hte environment, it will return an error.
ksh:
{topMiddleOligocenetoUpperEocene?}="something"
sh: {topMiddleOligocenetoUpperEocene?}=something: not found.
bash
{topMiddleOligocenetoUpperEocene?}="something"
bash: {topMiddleOligocenetoUpperEocene?}=something: command not found
Upvotes: 0
Reputation: 247012
Can't. That's not a valid identifier in bash. See the definition of name
at http://www.gnu.org/software/bash/manual/bashref.html#Definitions
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.
Upvotes: 5