≡ Menu

parameter expansion

HowTo: Bash Extract Filename And Extension In Unix / Linux

I have setup a shell variable called dest=”/nas100/backups/servers/z/zebra/mysql.tgz”. How do I find out filename (mysql.tgz) and extension (.tgz) in bash program running under Linux or Unix operating systems?
[click to continue…]

Sysadmin because even developers need heroes!!!

Bash Shell Count Number of Characters In a String or Word

How do I count and print particular character (say D or digit 7) in a string or variable under Bash UNIX / Linux shell?
[click to continue…]

Shell Scripting: If Variable Is Not Defined, Set Default Variable

If var is defined AND NOT EMPTY, use var, otherwise set a default variable under Bash. For e.g. my script needs a parameter for output variable. It can be text or html. I set it as follows in my script

output=$1 # either text or html

However, sometime user forget to pass the parameter to my shell script and my enter logic fails. So how do I set default value to text, if no parameter passed?
[click to continue…]