11 Jan 2012 @ 8:00 PM 


You remember we have talked about default variables earlier (Look here). Today, we are going to see an even more efficient way to cast default variables, for Bash users.

Note : The following only works in bash. Should you be unsure if the user of your function is going to use bash or ksh, you should use the way we have explained earlier.

So, this is the way to give a default value to a variable :

[ -z $var ] && var=’default’

The same command if you are using Bash :


It might look a bit more cryptic, but it’s the correct way to do it if you are sure to keep using Bash.

The right part of the :- operator can be a string, an integer or another variable.

Thank you for reading, and see you tomorrow !

Posted By: Dimi
Last Edit: 06 Jan 2012 @ 11:51 AM

Categories: Uncategorized


Responses to this post » (None)

Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


 Last 50 Posts
Change Theme...
  • Users » 67
  • Posts/Pages » 25
  • Comments » 4
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight