≡ Menu

shell scripting

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…]

Shell Scripting: Check File Size ( Find File Size )

How do I find out file size under UNIX / Linux operating system and store the same to a variable called s?
[click to continue…]

UNIX Shell: Find Out Real Path Of File or Directory

My programs and scripts needs a real path and not a a symbolic link. How to I determine a real path of any directory under Linux / UNIX like operating systems? How do I remove references to /./, /../ and extra '/' character in path?
[click to continue…]

BASH: Prepend A Text / Lines To a File

Q. I can append text to a file using >> operator but how do I prepend a text to a file? I want the opposit of >> operation?
[click to continue…]

Shell Scripting: Convert Uppercase to Lowercase

I've a small shell script and I would like to convert all incoming user input to lowercase using a shell script. How do I convert uppercase words or strings to a lowercase or vise versa on Unix-like / Linux bash shell?
[click to continue…]

How Do I Find The Largest Top 10 Files and Directories On a Linux / UNIX / BSD?

How do I find the largest top files and directories on a Linux or Unix like operating systems?
[click to continue…]