Hacker News new | past | comments | ask | show | jobs | submit login

'And guess what's the value of "HOME" in bash?'

In the rm line of the snippet above, "/some/location". Magic variables in bash tend to lose their magic once set.




I assume `set HOME = /some/location` is the tcsh syntax to set a variable.

In Bash, it doesn't do anything useful.


  > In Bash, it doesn't do anything useful.
In sh and derived shells, it sets the arguments ($1, $2, and so on). In this case you end up with $1 being ‘HOME’, $2 being ‘=’, and $3 being ‘/some/location’.


Ah, right, duh.


nope. try it: set HOME; echo $HOME.

on IRIX, $HOME for root is almost certainly root. So the resulting command is rm -rf /


I missed that set HOME doesn't set HOME (I was pre-coffee).

What I said about un-magic-ing is true for sure. "HOME=foo; echo $HOME" will print "foo".

Interestingly, it's propagated. "HOME=foo sh -c 'echo $HOME'" will also print "foo".




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: