Sunday, May 13, 2018

Usage Of Functions In Shell Scripting


Benefits of using functions inside shell scripting are:

- Less coding.
- Modular approach.
- Easy to understand.
- Exported as required for portability.
- Easy to expand or edit later.

As mentioned before, we could use functions inside shell scripting whenever required such as when there are set of codes which are common across some shell scripts then those common lines could be grouped into a function and called when required. Like-wise this approach of using functions would provide better readability, which is easier to understand, as well these functions could be amended independently. A group of codes put together to perform a specific task and defined with a name could be called as a function in shell scripting.

Saturday, March 3, 2018

Learn Shell Scripting In One Day


Let’s learn “Shell Scripting In a day”. So, in this post I wanted to talk about “What is a shell script?" & "learner guide to shell scripting with examples". Before jumping into learning on how to code and execute shell scripts, let’s talk a bit about “Linux” and history of Linux evaluation.

Linux is technically the kernel, so, there are other utilities such as GNU tools, GCC compiler etc,. which would ideally make a complete operating system (OS). That is the reason it is called GNU (GNUs not Unix) Linux not simply Linux. If I just say Linux then I’m talking about only the kernel.  GNU Linux is one of the widely used OS in market, because it is open-source, so anyone could download/re-use the kernel, publish a new Linux distribution under the guidelines of GPL & Free Software Foundation.

Learn Shell Scripting -- Part 2


Conditional operations using “if…else…fi” statement

We could use “if” statement when it is required to perform a conditional based operation. So, if the condition is true then process a set of commands, otherwise, process some other commands/action. The syntax of this is:

if [ <conditional statement> ]
then
< statements >    <--------- these statements gets executed if condition is true.
else
 < statements >   <--------- these statements gets executed if condition fails.
fi

Learn Shell Scripting -- Part 3


Let’s look into some of the commonly used built-in standard shell variables.

In this section we are going to see some of the standard shell built-in variables which we generally use in shell scripting.

#echo $? ---------- this would show the exit status of the previous command run in shell (0 - success, anything other than 0 is considered as failure)
#echo $$ ---------- this shows current shell ID (when run inside a script this would print the PID assigned to
the shell).
#echo $@ OR #echo $* ---------- this prints the arguments passed when called for execution.
#echo $# ---------- this would show up total number of arguments passed.
#echo $! ---------- this would report PID of previous background process.
#echo $_ ---------- this would print last argument being used in the previous command in shell.

Friday, February 2, 2018

A few advanced differences between RHEL7.x & RHEL6.x



Extracting initramfs image :--
---------------------------------------



Using "skipcpio" command in RHEL7.x, otherwise, we use "gunzip" in earlier RHEL versions. So, the command to extract initramfs image file in RHEL7.x is " /usr/lib/dracut/skipcpio /boot/initramfs-$(uname -r).img | gunzip -c | cpio -id ". In earlier versions, we could do this by using the command gunzip "gunzip -c /boot/initramfs-$(uname -r).img | cpio -i -d ".