# difference between $variable and ${variable}

**URL:** <https://community.unix.com/t/difference-between-variable-and-variable/170476>\
**Category:** Shell Programming and Scripting\
**Created:** [April 12, 2007, 7:33am UTC](https://community.unix.com/t/difference-between-variable-and-variable/170476 "2007-04-12T07:33:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hcclnoodles](https://community.unix.com/letter_avatar/hcclnoodles/32/6_449c533f586939b6e5f246632a46421f.png) [@hcclnoodles](https://community.unix.com/u/hcclnoodles)\
**Post date:** [April 12, 2007, 7:33am UTC](https://community.unix.com/t/difference-between-variable-and-variable/170476/1 "2007-04-12T07:33:27Z")

</div>

Hi there

Simple question im sure but what is the difference between $variable and ${variable}

ie I have seen scripts like this

```nohighlight
for user in gary peter paul ; do
   chown -R ${user}:other /data/trans
done

```

and some that do this

```nohighlight
for user in gary peter paul ; do
   chown -R $user:other /data/trans
done

```

what is the difference

Cheers

---

<div class="post-metadata">

**Author:** ![Yogesh\_Sawant](https://community.unix.com/user_avatar/community.unix.com/yogesh_sawant/32/22562_2.png) [@Yogesh\_Sawant](https://community.unix.com/u/Yogesh_Sawant)\
**Post date:** [April 12, 2007, 7:42am UTC](https://community.unix.com/t/difference-between-variable-and-variable/170476/2 "2007-04-12T07:42:49Z")

</div>

this might put some light on the matter:

```nohighlight
#!/bin/bash
t=100
echo $t
echo $tea
echo ${t}ea

```

---

<div class="post-metadata">

**Author:** ![vino](https://community.unix.com/user_avatar/community.unix.com/vino/32/156_2.png) [@vino](https://community.unix.com/u/vino)\
**Post date:** [April 12, 2007, 7:55am UTC](https://community.unix.com/t/difference-between-variable-and-variable/170476/3 "2007-04-12T07:55:52Z")

</div>

From man sh

```nohighlight
   Parameter Expansion
       The ?$? character introduces parameter expansion, command substitution,
       or arithmetic expansion. The parameter name or symbol to be expanded
       may be enclosed in braces, which are optional but serve to protect the
       variable to be expanded from characters immediately following it which
       could be interpreted as part of the name.

       When braces are used, the matching ending brace is the first ?}? not
       escaped by a backslash or within a quoted string, and not within an
       embedded arithmetic expansion, command substitution, or paramter expan-
       sion.

       ${parameter}
              The value of parameter is substituted. The braces are required
              when parameter is a positional parameter with more than one
              digit, or when parameter is followed by a character which is not
              to be interpreted as part of its name.

```

See this

```nohighlight
[/tmp]$ cat try.sh
#! /bin/sh

a=12
b=34
echo $a_$b
echo ${a}_$b
[vivarkey@/tmp]$ sh try.sh
34
12_34
[/tmp]$ 

```

---

<div class="post-metadata">

**Author:** ![hcclnoodles](https://community.unix.com/letter_avatar/hcclnoodles/32/6_449c533f586939b6e5f246632a46421f.png) [@hcclnoodles](https://community.unix.com/u/hcclnoodles)\
**Post date:** [April 12, 2007, 7:56am UTC](https://community.unix.com/t/difference-between-variable-and-variable/170476/4 "2007-04-12T07:56:48Z")

</div>

ah thankyou
