Categories
General Shell script technews

Bug in Bash shell allow attackers to execute code on Linux, Unix and Mac OSX

A security vulnerability in the GNU Bourne Again Shell (Bash), the command-line shell used in many Linux and Unix operating systems, could leave systems running those operating systems open to exploitation by specially crafted attacks. The bug, discovered by Stephane Schazelas, is related to how Bash processes environmental variables passed by the operating system or […]

Categories
Loops

if…else…fi

If given condition is true then command1 is executed otherwise command2 is executed. Syntax: if condition then condition is zero (true – 0) execute all commands up to else statement else if condition is not true then execute all commands up to fi fi example of nested if else osch=0 echo “1. Unix (Sun Os)” […]

Categories
Loops

if condition

if condition which is used for decision making in shell script, If given condition is true then command1 is executed. Syntax: if condition  then  command1 if condition is true or if exit status of condition is 0 (zero)  …  …  fi

Categories
Shell script

Pipes

A pipe is a way to connect the output of one program to the input of another program without any temporary file. Syntax: command1 | command2 eg: who | wc -l   Output of who command is given as input to wc command So that it will number of user who logon to system

Categories
Shell script

Command line arguements

eg: $ myshell foo bar  Shell Script name i.e. myshell  First command line argument passed to myshell i.e. foo  Second command line argument passed to myshell i.e. bar In shell if we wish to refer this command line argument we refer above as follows  myshell it is $0  foo it is $1  bar it is […]

Categories
Shell script

Wildcards

Wildcard types: 1. *  – Matches any string or group of characters. 2. ?  – Matches any single character. 3. […]  – Matches any one of the enclosed characters Note:  [..-..] A pair of characters separated by a minus sign denotes a range.

Categories
Shell script

The read statement

Use to get input (data from user) from keyboard and store (data) to variable. Syntax:  read variable1, variable2,…variableN   eg: #!/bin/sh echo “Enter your name please” read fname echo “Welcome $fname”

Categories
Shell script

Exit status

By default in Linux if particular command/shell script is executed, it return two type of values which is used to see whether command or shell script executed is successful or not. (1) If return value is zero (0), command is successful. (2) If return value is nonzero, command is not successful or some sort of error executing command/shell […]

Categories
Shell script

Quotes in scripts

Mainly three types of quotes are used. 1. ” – Double quotes: Anything enclose in double quotes removed meaning of that characters (except and $). 2. ‘ – Single quotes: Enclosed in single quotes remains unchanged. 3. ` – Back quotes: To execute command    

Categories
Shell script

Shell Arithmetic

used to perform arithmetic operations in shell scripts. Synatax: $ expr  op1 operator  op2 eg: $ expr 1 + 3 $ expr 2 – 1 $ expr 10 / 2 $ expr 20 % 3 $ expr 10 * 3 $ echo `expr 6 + 3` in the last one we used back quote (` […]