Showing posts with label bash scripting. Show all posts
Showing posts with label bash scripting. Show all posts

Wednesday, December 29, 2010

How to use multiple line comments in bash scripting

All single line comments in bash begin with # symbol, except for the first line (#!/bin/bash)
e.g.;
# this is an example of single line comment.

You can use HERE DOCUMENT feature to create multiple line comment

<<MULTILNCMNT
welcome to the go2linuxworld.blogspot.com
this is an example of
multiple line comment
in bash
MULTILNCMNT

Tuesday, December 28, 2010

How to debug a bash script in Linux

To debug a bash script, you need to run a shell script with -x option from the command line itself:
bash -x scriptname
or
bash -xv scriptname

You can also modify shebang line to run an entire script in debugging mode.

#!/bin/bash -x
echo "Hello ${USER}"
echo "Today is $(date)"

Monday, December 27, 2010

How to execute a scirpt in Linux

A shell script can be executed using the following syntax
chmod +x script.sh
./script.sh

You can also run the script directly without setting the script execute permission
bash script.sh
or
source script.sh
or
. script.sh

In the last example we are using . (dot) or source command which reads and executes commands from filename in the current shell.
When a script is executed using either the bash command or the source (.) command, you don't have to set execute permission on script.

reference: http://www.cyberciti.biz