You are on page 1of 3

What are the different methods available to run a shell Script?

3 ways

1. .sh
2.If the script has execute permission - ./

3. If the script has execute permission and is stored in the directory listed in PATH or

what are special characters and explain how does text varies by the usage of single
quotes,double quotes and back quotes?

Special character like %,$,&,? are taken differently in unix as they have some different meaning and

backslash (\) is used to mask the special meaning of these special character immidietly following it.

example is grep 'hello\.gif' file

Here \ is used to mask . as it will show the hidden file in unix directory.

Double Quotes( "" )-- Anything enclose in double quotes removed meaning of that characters
(except \ and $).

example: %echo "Today is date"

Today is date

Single quotes( '' )--Enclosed in single quotes remains unchanged.

Back quote( `` )--To execute command

%echo "Today is `date`"

Today is Mon Aug 11 05:33:46 EDT 2008

How to take input values from the user?

1. using read command
2. reading input from a file

How to print some text on to the screen?

echo "Text to print"

What are the different shells available?

BASH Shell (common Shell)
CSH( C Shell)
KSH(Korn Shell)

How to modify the PATH variable and make it executable?

we can set PATH by using export PATH command.
export PATH

and to make it executable we can set the same

in ".bash_profile".

To execute it ". .bash_profile"

When we login into our account which files are executed?

In which variable prompt value is stored?

How to make userdefined variables to available for all

other shells?

By exporting the variable

export VAR=value_of_the_variable

How to create environment variables? What are the conditions for creating variables?
We can create environment variable by using export command.(Also by using set, but difference
between set and export is the which has been exported is being available in cloned/child shell.) export
VAR="Welcome"But problem is this variable has life span of session only. For making it permanent we
need to put that in login script.

How to change our default shell?

Using 'chsh'
chsh -s <shell_name>

How to customize the existing shell?

The first line in the shell script should be modified as:

How will you list only the empty lines in a file (using grep)?
grep "^$" filename

How would you print just the 25th line in a file using smallest shell script?
head -25 filename | tail -1

When you login to a c shell, which script would be run first?

.cshrc file will be read each time you start a new csh or tcsh shell

How would you replace the n character in a file with some xyz?
* sed 's/n/xyz/g' filename > new_filename
s -search and replace
n -character to be replaced
xyz - character to replace
g -global

* vi filename
:%s/n/xyz/g --search and replace
:w! ---save

What is MUTEX?
Mutex is a program object that allows multiple program threads to share the same resource, such as
file access, but not simultaneously. When a program is started a mutex is created woth a unique
name. After this stage, any thread
that needs the resource must lock the mutex from other threads while it is using the resource. the
mutex is set to unlock when the data is no longer needed or the routine is finished.

What is the difference between a shell variable that is exported and the one that is not exported?
the major difference between the shell variable that is exported and not is variable exported using
export command is global to all shell,where as the other shell variables are local to their respective
What is the difference between a 'thread' and a 'process'?
Process is a program in execution whereas thread is a separate path of execution in a program.
Process & Thread share almost all datastructure except (thread has it's own register & stack area).
Process is a program under execution,but thread is a light weight process which has seperate way of
execution.Threads are part of process.Single process can contain number of threads at a time.

A process is a collection of virtual memory space, code,data, and system resources.

All thread with in a process share process instruction,code & data segment,open file descriptor,signal
handler,userID and GroupID.

Thread has its own set of register including program counter,stack pointer

How Connect to a Database in Shell Programming?

you have a "sqlplus" command to connect to database.

command is as follows:
sqlplus <db_username>/<db_password> @test.sql

what is this line in the shell script do ?#!/bin/ksh

to execute the commands in a script using "ksh" shell.

What is the basic difference you find between a shell script and perl?
Shell script is platform(OS) only for Unix
flavour,dependent whereas perl is OS independent

what is the difference between writing code in shell and editor?

What are the three main forms of enabling debugging in a shell script?
set -x
set -v
set -n