You are on page 1of 4

Comments:

=========
#
Variables:
===========
var-name=value_without_space
var-name="value with space"
var-name=$var-name
echo $var-name
Getting command output:
=======================
var=$(command)
Execute command with echo:
===========================
echo $(command)
Expression:
============
echo $((1 + 2 + 3))
expr 1 + 2 + 3
expr $var1 + $var2 + $var3 + 5
Execute command in string:
==========================
echo "today is 'date'"
echo "today is $(date)"
Conditional Operator:
======================
-eq, -ne, -lt, -gt, -le, -ge, -a, -o, !
Conditional Operator For String:
=================================
string1 = string2, string1 != string2
string1(not null/not defined), -n string1(not null and exist), -z string1(null a
nd exist)
Conditional Operator For File:
=================================
-s file(not empty file), -f file(file exist/normal file/not a directory)
-d file(directory exist/not a file), -w file(writeable file)
-r file(readable file), -x file(executable file)
Control Structure:
===================
if [ condition ]
then
statements....
elif [ condition ]
then
statements....
else
statements....
fi
Looping:
========

while [ condition ]
do
statements...
done
-for var-name in space_seperated_val_list
do
statements...
done
-case value
in
value) statement.... ;;
value) statement.... ;;
*) default statement.... ;;
esac
Loop/Program Terminator:
=========================
exit
exit 0
exit 1
Functions (always declared at first):
======================================
function-name () {
local var-name=value
#function variable
local var-name=$var-name #function variable
passing parameters are taken by $1, $2, $3 ....
statements...
print value using echo for returning value...
return
}
Calling Function:
==================
function-name
var=$(function-name) #getting return value
function-name $param1/value1 $param2/value2
var=$(function-name $param1/value1 $param2/value2) #getting return value
Importing Functions:
=====================
You can declare the functions into separate file and import that file in your pr
ogram by:
. directory/file-name
Reading input from user:
=========================
read var-name
Reading command line argument:
==============================
$0(command-name), $1, $2, $3, ......
$#(return number of arguments)
Checking command status:
=========================

echo $? (0 for successful command otherwise un-successful command)


Conditional command execution:
===============================
command1 && command2 || command3
(if command1 is successful then command 2 will be executed otherwise
command2 will be executed)
Running multiple command together:
==================================
command1;command2;....

Show Dialog:
================================================================================
===============================
dialog
[--title <title>] [--backtitle <backtitle>] [--yes-label <str>] [--cancel-label
<str>]
[--extra-button] [--exit-label <str>] [--beep-after] [--begin <y> <x>] [--clear
]
[--colors] [--column-separator <str>] [--cr-wrap] [--date-format <str>]
[--default-button <str>] [--default-item <str>] [--defaultno] [--extra-label <s
tr>]
[--help-button] [--help-label <str>] [--help-status] [--hfile <str>]
[--hline <str>] [--ignore] [--input-fd <fd>] [--insecure] [--item-help]
[--keep-tite] [--keep-window] [--max-input <n>] [--no-cancel]
[--no-collapse] [--no-cr-wrap] [--no-items] [--no-kill]
[--no-label <str>] [--no-lines] [--no-mouse] [--no-nl-expand]
[--no-ok] [--no-shadow] [--no-tags] [--nook] [--ok-label <str>]
[--output-fd <fd>] [--output-separator <str>] [--print-maxsize]
[--print-size] [--print-version] [--quoted] [--scrollbar]
[--separate-output] [--separate-widget <str>] [--shadow]
[--single-quoted] [--size-err] [--sleep <secs>] [--stderr] [--stdout]
[--tab-correct] [--tab-len <n>] [--time-format <str>] [--timeout <secs>]
[--trace <file>] [--trim] [--version] [--visit-items]
[--ascii-lines] [--aspect <ratio>] [--beep] Box Option
Box options:
--buildlist
<text> <height> <width> <tag1> <item1> <status1>...
--calendar
<text> <height> <width> <day> <month> <year>
--checklist
<text> <height> <width> <list height> <tag1> <item1> <status1>...
--dselect
<directory> <height> <width>
--editbox
<file> <height> <width>
--form
<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <ite
m1> <i_y1> <i_x1> <flen1> <ilen1>...
--fselect
<filepath> <height> <width>
--gauge
<text> <height> <width> [<percent>]
--infobox
<text> <height> <width>
--inputbox
<text> <height> <width> [init(0,2)>filename]
--inputmenu
<text> <height> <width> <menu height> <tag1> <item1>...

--menu
<text> <height> <width> <menu height> <tag1> <item1>...
--mixedform
<text> <height> <width> <form height> <label1> <l_y1> <l_x1> <ite
m1> <i_y1> <i_x1> <flen1> <ilen1> <itype>...
--mixedgauge <text> <height> <width> <percent> <tag1> <item1>...
--msgbox
<text> <height> <width>
--passwordbox <text> <height> <width> [<init>]
--passwordform <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <ite
m1> <i_y1> <i_x1> <flen1> <ilen1>...
--pause
<text> <height> <width> <seconds>
--prgbox
<text> <command> <height> <width>
--programbox <text> <height> <width>
--progressbox <text> <height> <width>
--radiolist
<text> <height> <width> <list height> <tag1> <item1> <status1>...
--rangebox
<text> <height> <width> <min-value> <max-value> <default-value>
--tailbox
<file> <height> <width>
--tailboxbg
<file> <height> <width>
--textbox
<file> <height> <width>
--timebox
<text> <height> <width> <hour> <minute> <second>
--treeview
<text> <height> <width> <list-height> <tag1> <item1> <status1> <d
epth1>...
--yesno
<text> <height> <width>
================================================================================
=========================================================

You might also like