Sponsored Content
Full Discussion: What does ${x} mean?
Top Forums Shell Programming and Scripting What does ${x} mean? Post 303031695 by rbatte1 on Monday 4th of March 2019 12:17:04 PM
Old 03-04-2019
The { and } are very useful for clarity. It is also very useful for these cases too:-
  • You want to refer to command line parameter ten or over. Some OSes would interpret $10 as actually the first parameter suffixed with a zero. You would need to refer to ${10} instead.
  • You might want to refer to a variable and put in a suffix of your own, then $var_suffix will not work, but ${var}_suffix will. The _suffix will be treated as though it is part of the variable name with the first format, but is just literal text appended after the value of the variable in the latter.

The second case might be a bit obscure, so perhaps a demonstration on the command line is better:-
Code:
$ a=Hello
$ a_b=world
$ echo $a
Hello
$ echo $a_b
world
$ echo ${a}_b
Hello_b



I hope that this helps and that I haven't confused things.
Robin

Last edited by rbatte1; 03-05-2019 at 06:41 AM.. Reason: Corrected my example. Oh how wrong I was trying to illustrate the issue but getting it backwards!
These 3 Users Gave Thanks to rbatte1 For This Post:
 
All times are GMT -4. The time now is 09:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy