GeekInterview.com
Series: Subject: Topic:

Shell Scripting Interview Questions

Showing Questions 21 - 40 of 55 Questions
First | Prev | | Next | Last Page
Sort by: 
 | 

Using bourne shell : if you enter a b C d e f g.......................N after the command,how will you write a programme to reverse these positional parameters?

Asked By: Nehashri | Asked On: Feb 4th, 2007

Answered by: shilpa keesara on: Aug 7th, 2011

Using KSH while loop#!/bin/ksh
#Get the count of total number of arguments passed while executing this script
int i = $#; #total number of arguments passed#
names=$@; #list of actual arguments passed#
while [ ${i} -gt 0 ]
do
echo '${names[i]}';
i=`expr i - 1`;
done
exit 0;

Answered by: abdas on: Jul 26th, 2011

$ cat rev2
i=$#
echo "$@" > file_1

while [ $i -gt 0 ]
do
cut -f $i -d" " file_1 >> file_2
i=`echo $i-1|bc`
done

echo `cat file_2`;
rm -f file_1 file_2;

$ sh rev2 A B C D E
E D C B A

If you have a string "one two three", which shell command would you use to extract the strings?

Asked By: Interview Candidate | Asked On: Jul 27th, 2005

Answered by: abdas on: Jul 25th, 2011

Code
  1. echo $1
  2. echo $2
  3. echo $3

Answered by: iamjogi on: Aug 23rd, 2009

Try this:

echo "one two three" | xargs

the output is: one two three

UNIX security mechanisms

Asked By: super_sixes | Asked On: Sep 26th, 2008

What are the different security mechanisms available in UNIX?

Answered by: Gunjan David on: Jun 27th, 2011

a) vi /etc/default/login
comment the line of /dev/console

b)vi .rhosts
enter the hostname by which the only user can connect with your system....bt no one else.....
c) disable the ftp for the selected users in /etc/ftpusers file ...

Answered by: Deepa_0982 on: Jan 21st, 2009

Unix is having 3 ways of Security Mechanism:1. By granting or revoking File permissions. Owner or Admin can change permissions to be given to group or others by using chmod command in Unix.2. Login is...

Shell scripting commands

Asked By: siddhishah_999 | Asked On: Apr 28th, 2009

In shell scripting how to indentify that the previous command was run successfully?

Answered by: abdas on: Jun 26th, 2011

in 2 ways it can be done:
1st way
$ echo $?  

2nd way:

$ pwd 2> error| cat error|wc -l
       0
$ cat h 2> error| cat error|wc -l
       1

pwd or cat or any command if outpt is 0 then successful else failed.

Answered by: Nagunix on: Jun 6th, 2010

Use command

echo $?

at prompt.

If the output of command is 0 than succesfully executed.
If the output is non -zero than not successfully executed.

Shell script to track file changes

Asked By: iblue | Asked On: Jun 20th, 2009

Write a shell script to save the output of 'ls -ltr' every five minutes and after every hour it should print which all files are changed/modified/created.

Answered by: abdas on: Jun 26th, 2011

find $HOME -mmin -5 -ls     # run the same in cron

Answered by: swetha_0505 on: Oct 26th, 2009

find . -mtime 0   # find files modified between now and 1 day ago (i.e., within the past 24 hours)find . -mtime -1  # find files modified less than 1 day ago (i.e., within the past...

Join two csv text files

Asked By: bubgem27 | Asked On: Apr 18th, 2010

Write a shell script to join two csv text files based on value of some columns?

Answered by: abdas on: Jun 26th, 2011

cat file1 file2 >  file3

Answered by: nkumar85 on: May 18th, 2010

Bash does not support this kind of feature, you can do this in PERL, because PERL supports all feature which are needed to work with CSV worksheets.

How to compare floating point number in shell scripting ?

Asked By: Sanjay | Asked On: Aug 14th, 2007

Answered by: abdas on: Jun 23rd, 2011

a=10.50
b=11.01

if [ $a -gt $b ]
        then
        echo a is greater than b
else 
        echo a is less than b
fi

Answered by: balaksara on: Nov 29th, 2008

a1=10.50

b1=11.01

st=$(echo "$a1 > $b1" | bc)

if [ $st -eq 1 ];

then

# 1 == true

echo "True"

else

echo "False"

fi

What is the difference between a shell variable that is exported and the one that is not exported?

Asked By: Interview Candidate | Asked On: Jul 27th, 2005

Answered by: nitashaa on: Jul 18th, 2008

global variable is created using export command in ksh - export x='name' In csh its created using setenv command-setenv x 'name'this 'x' variable will be visible in curren...

Answered by: riteshvado on: Aug 13th, 2007

try this simple script it will clear your concept :-

script a.sh :-
----------
export A=3
B=5
sh b.sh
--------

script b.sh :-
-----------
echo "exported variable $A is :- $A"
echo "Variable $B -- $B "

---------

A persists in b.sh whereas B doesn't.

Different types of shells?

Asked By: Interview Candidate | Asked On: Aug 22nd, 2005

Answered by: vijayanand86 on: Jan 20th, 2010

K Shell,
Bourne Shell,
Bash,
C-Shell

Answered by: cmanne on: Mar 25th, 2007

ashell
bshell
bash (born again shell)
cshell
kshell
zshell

What is $*?

Asked By: Interview Candidate | Asked On: Jul 29th, 2005

Answered by: vijayanand86 on: Jan 20th, 2010

Contains the list of arguments passed to the function.

Answered by: vidyamurali2003 on: Dec 30th, 2008

It contains the actual arguments passed to a shell script

How do you schedule a command to run at 4:00 every morning?

Asked By: Interview Candidate | Asked On: Jul 5th, 2005

Answered by: amrashri on: Apr 10th, 2011

crontab 0 4 * * * command



Answered by: Jyotiranjan Mohanty on: Apr 7th, 2007

1st step$ cat > cmdfile//<Minute> <Hour> <Day Of Month> <Day Of Week> <Command>    0           &n...

How connect to a database in shell programming?Please tell me step by step?

Asked By: Brahma Reddy Thatiparthi | Asked On: Mar 26th, 2006

Answered by: Anubhaw.Agrawal on: Apr 22nd, 2010

$ORACLE_HOME/bin/sqlplus username/password@remote_db

Answered by: Vamshidhar on: Jan 14th, 2009

IF the Database is DB2 then the script is :

db2 "connect to $dbname user $userid using $password"

Shell script

Asked By: Namataraginu | Asked On: Jan 31st, 2008

You have current directory containing set of directories which contain files.One file can reside in many directories.Write script which returns number of unique file names inall the subdirectories of a current dir.

Answered by: nishi11 on: Feb 22nd, 2010

ls -pR | grep -v "/" | grep -v ":" | sort |uniq

Answered by: tangram on: Jan 27th, 2010

ls -R | grep -v "/" | sort | uniq

grep -v "/"  -- is used to filter out directories

Write a shell script to identify the given string is palindrome or not?

Asked By: athotaashok | Asked On: Feb 21st, 2006

Answered by: my_thoughts on: Feb 14th, 2010

read string1
string_rev=`rev string1`
if [ string1 = string_rev ]
then
 echo palindrome
else
 echo not a palindrome
fi

Answered by: Vivek12 on: Jun 4th, 2008

echo enter a string read stringlen=`expr length "$string"`i=$lenreverse=''while [ $i -gt 0 ]dochar=`echo $string | cut -c $i`reverse="$reverse$char"i=`expr $i - 1`doneecho ...

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

Asked By: Max | Asked On: Jun 22nd, 2006

Answered by: my_thoughts on: Feb 14th, 2010

#! at the start of the file indicates that this is a shell script file, rather than a normal file./bin/ksh -- runs the shell script in ksh shell.By default the shell script runs in the current shell (...

Answered by: ajit_saley on: Feb 4th, 2009

#! line states the interpreter to be used by the shell to interpret the script.

Here, ksh interpreter is invoked for interpretation of the script.

What are the different kinds of lOOPS available in shell script?

Asked By: Interview Candidate | Asked On: Jul 5th, 2005

Answered by: amverma10 on: Jan 4th, 2010

While loopThe syntax for while is: while conditiondo statements...done For loopsThe syntax for the for loop: for name [in list]do statements that can use $name...done Untill loopsThe ...

Answered by: kabhishek on: Dec 11th, 2009

3 loops

for
while
until  --> Just reverse of while loop

-----------------------
"if-elif" or "if else" or "case" not comes in the loop

What are the steps to take files from UNIX server to windows?

Asked By: Dipti | Asked On: Jan 10th, 2007

Answered by: abrenar on: Nov 4th, 2009

Most UNIX servers are configured not to use FTP or TELNET for security purposes, and if you use FTP it has limited number of data can be transfered on one transaction hence I preferred using another w...

Answered by: UncaAlby on: Nov 8th, 2008

If you can't get Samba, or you're not the Admin so you can't install it anyway, then use FTP, as it's almost guaranteed to be installed and running on both machines.  The only han...

Uid and gid

Asked By: super_sixes | Asked On: Sep 26th, 2008

What does uid and gid signify?

Answered by: swetha_0505 on: Oct 26th, 2009

To find a user's UID or GID in Unix, use the id command. To find a specific user's UID, at the Unix prompt, enter: id -u username Replace username with the appropriate user's username. To find ...

Answered by: Vijaymorey on: Apr 28th, 2009

UID - User idGID - Group idWe can find out using sample command fire @ $ promoit "id" you will user id & group id.e. g step 1 : $ id ---> O/p get display immediately uid=232(vi...

Write a script to convert all dos style backslashes to UNIX style slashes in a list of files?Write a script to list all the differences between two directories ?What is the command for to display the last...

Asked By: ashok | Asked On: Aug 17th, 2007

Answered by: sorkan on: Sep 7th, 2009

dos2unix only removes the control-M characters at the end of the line.  You need to use sed to do the search and replace for '' to '/'.

Answered by: amitkshirsagar on: Jun 17th, 2009

Command to list all the differences between two dir:

diff -r > diff.txt

Diff.txt will show you all the differences.

How to compare two floating point numbers ?

Asked By: Jitu | Asked On: Mar 25th, 2007

How to perform the arithmetic operations on floating point numbers ?

Answered by: abhimishraoist on: Aug 18th, 2009

We can use test also in command line

test 1.2 -gt 1.1 | echo "abhishek"

You will get o/p

abhishek.

Answered by: Gaurav on: Apr 17th, 2007

You can make you og 'bc' command to do the arithmatic operations in shell script.
Following script illustrates a sample implimentation

a=1.2
b=3.1
x=$(echo $a+$b|bc)
echo [$x]

Where the arithmatic operation that is desired is marked in bold.

First | Prev | | Next | Last Page

 

 

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.