3

I have the following :

x=/
find ${x} *

Now this is similar to find / *

What is the significance of $ and {} in find ${x} *

0

1 Answer 1

2

$... denotes a variable, and when followed by curly parenthesis ${...}, you provide a boundary for the variable so you can run it next to a string literal like:

$ FLAVOUR="cheese"
$ echo "I like ${FLAVOUR}y crisps"
I like cheesey crisps

Without the parenthesis, you would see:

$ echo "I like $FLAVOURy crisps"
I like  crisps

Which, while true, isn't what you really wanted.

Why it's used in your example is beyond me. It isn't required.


Curly braces are also used for bash array lookups when you want to specify the index, but this has nothing to do with your example:

$ arr=(*)
$ echo ${arr[3]} # print third item; 1-indexed? blimey.
jumbo-small.jpg
$echo ${arr[@]} # print whole array
glyphicons-halflings.png glyphicons-halflings-white.png jumbo.jpg jumbo-small.jpg
1
  • Thanks, that answer my question. Since I am a beginner so just playing around. Agreed find ${x} * is not required, however was trying to understand the deeper meaning.
    – Vidisha
    Jun 20, 2013 at 11:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .