Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 2
    I am wondering why you haven't mentioned the standard way; to assign to a variable, to use just: x=1. - All the variants you mention make use of side effects of a variable expansion; they have there uses, and it seems you've got answers that explain the differences. Commented Jun 17, 2015 at 5:21
  • 1
    Try echo $x after each of those and you will see if it actually assigns anything to the variable. This syntax is actually for reading (expanding) the variable (with side-effects, which may also modify the variable, but not in all the cases you mentioned). Commented Jun 17, 2015 at 8:12
  • 1
    There are in fact, more ways. x=1, let x=1, ((x=1)), read x <<< 1, eval x=1, and probably others. Commented Jun 17, 2015 at 16:24
  • 1
    There are more ways. *nix is about having options. Many great tools with many great options. This way you don't have as many obstacles as 'programming languages'. Commented Jun 17, 2015 at 18:46