Curly braces assigned to variables

Hi,

Im pretty new to Unix. I came across a script which was using PLSQL inside a script and there was an unusual thing mentioned.

there was a variable assigned as

P_CUR=${1}  

and one more as

V_TAGFILE="$1"

Couldnt find the difference. Also the variables were used in PLSQL commands. Will be really thankful if someone clears this doubt.

Warm Regards,
Krupa

${1} is the same as $1 which is the first positional parameter for a shell. The curled brackets are not needed in this case. They are used to border variable names from other characters and symbols right next to them so that the shell has no problem to find the variable name.

Using double quotes arround a variable definition is for preserving blanks etc. and define all inside the double quotes as content/value of the variable all together. Example:

$> VAR=a b
-bash: b: command not found
$> echo $VAR

It returns an error since a definition of a value for variable can only be 1 element. If you have several elements, as here delimeted by a blank, you'll need those double quotes around.

In the case of your script, it depends what $1 can contain, but having double quotes around it when assigning it to some variable isn't a bad idea at all.

1 Like