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*

9
  • If I run random=$(bash -c "RANDOM=640; echo $RANDOM") shouldn't it return the same each time? Or is it because the $(bash ... isn't treated as a new instance of bash? Commented Nov 17, 2017 at 17:47
  • 1
    doublequotes is probably not what you want there Commented Nov 17, 2017 at 17:55
  • 1
    Watch what happens if you do: set -x; FOO=42; bash -c "FOO=999; echo $FOO". The double-quotes are allowing the outer shell to replace $RANDOM with the outer shell's random; the inner bash shell is simply echoing an integer. Commented Nov 17, 2017 at 17:56
  • @thrig I need double quotes because in my case it is actually random=$(bash -c "RANDOM=$mac; echo $RANDOM") Commented Nov 17, 2017 at 17:56
  • Of course it should be bash -c 'RANDOM=42; echo "$RANDOM" "$RANDOM" "$RANDOM"'. Commented Nov 18, 2017 at 0:58