≡ Menu


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

Sysadmin because even developers need heroes!!!

HowTo: Skip Bash For Loop

How do I skip bash for loop if certain condition is satisfied under UNIX / Linux / BSD / OS X?
[click to continue…]

BASH: Prepend A Text / Lines To a File

I am a new Unix system user with a bash as a default shell. I can append text to a file using >> operator but how do I prepend a text to a file? I want the opposite operation of >>. How can I prepend some data to a text file?
[click to continue…]

Linux: pathmunge Command in Shell Script

Q. I see pathmunge used in few scripts under Red Hat Enterprise Linux. Can you explain the use of pathmunge under RHEL / CentOS / Fedora Linux?
[click to continue…]

How do I Be More Productive In Vim?

This is a user contributed FAQ.

Q. I’m just starting in vim text editor but I’m annoying typing and retyping similar statements. Can you address me about it?
[click to continue…]

FreeBSD Install BASH Shell

I would like to Bash shell under FreeBSD for bash programming. How do I install bash shell under FreeBSD UNIX operating system?
[click to continue…]

How To Run the .sh File Shell Script In Linux / UNIX

I’ve downloaded software for Linux or Unix-like system from the Internet. There is a file called install.sh. How do I run an .sh file to install the software?
[click to continue…]

Shell Script Put Multiple Line Comment

I would like to use multiline comments under shell script. Under C / C++ I can use the following format

my c code
comment # 2
foo bar

How do I put multi line comment under a shell script?
[click to continue…]

How to use bash shell

Q. How do I use bash shell? What command I need to type use bash shell?

A. GNU Bourne-Again Shell is default shell on most Linux systems (distributions). So when you open terminal from X Windows (KDE/Gnome) you directly opens a bash shell. Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file.

To find out your shell version type:
$ echo $SHELL


If you are using different shell, just type bash at command prompt and load bash shell:
$ bash

Bash Grep Subdirectories (Recursively)

How do I recursively grep through all sub-directories and find files containing given text / string or words?
[click to continue…]