# sh scripts syntax ":"



## nORKy (Apr 15, 2011)

What does ":" mean in sh scripts ?
ex:


> : ${mysql_limits="NO"}


----------



## graudeejs (Apr 15, 2011)

The entire statement is invalid

http://www.grymoire.com/Unix/Sh.html


----------



## graudeejs (Apr 15, 2011)

if it was something like


```
$mysql_limits=${mysql_limits:-"NO"}
```
Then it would mean: set mysql_limits to NO if it's not defined already


----------



## SirDice (Apr 15, 2011)

killasmurf86 said:
			
		

> The entire statement is invalid


No, it's not. It's even defined as a POSIX standard.

The : (colon) means do nothing except expanding arguments and redirections. The return status is always 0.


----------



## SirDice (Apr 15, 2011)

I couldn't find an explanation on a short notice but I did find this, perfectly legal, shell script:

```
:(){ :|:& };:
```

*WARNING WARNING WARNING* Do not run this on your production system(s)!!!


----------



## pbd (Apr 15, 2011)

SirDice said:
			
		

> *WARNING WARNING WARNING* Do not run this on your production system(s)!!!



I would rather say, don't run it at all..


----------



## graudeejs (Apr 15, 2011)

looks like fork bomb (not sure)


----------



## SirDice (Apr 15, 2011)

killasmurf86 said:
			
		

> looks like fork bomb (not sure)



It is :e


----------



## UNIXgod (Apr 15, 2011)

SirDice said:
			
		

> I couldn't find an explanation on a short notice but I did find this, perfectly legal, shell script:
> 
> ```
> :(){ :|:& };:
> ...



But it smiles at you. must ... resist ... exec arbitrary code ...

The fork bomb is pretty famous. I posted it once on irc after being reminded of it on  slashdots stupid unix tricks (http://ask.slashdot.org/story/08/11/05/2027234/Useful-Stupid-Unix-Tricks)

None the less one of the mods asked me to never post such a thing again... ever =)


----------

