Shell Script Interview Question and Answers part 3 ?
echo $SHELL
|
./process-name &
|
$1, $2 and so on. $0 is your script name.
|
if then … fi
|
-eq, -ne, -lt, -le, -gt, -ge
|
-s filename tells you if the file is not empty, -f file...
|
! tests for logical not, -a tests for logical and, and ...
|
$#
|
if then elif fi
|
for in do done
|
while do done
|
case in ) ;; ) ;; esac
|
read
|
function-name()
|
kill 0
|
ps -ag
|
kill pid
|
date
|
who
|
pwd
|
rm
|
rm -rf
|
whoami
|
mail somebody@interviewduniya.com -s ‘Your subject’ -c ...
|
wc
|
grep string filename
|
grep string *
|
grep -r string *
|
29. What are PIDs?
They are process IDs given to processes. A PID can vary...
|
ps
|
#################################################################################
1. How to print nth column of a pattern/file without using awk,cut commands?
awk {print $n} < filename
where n is the field number
2.How to extract the second row of a text-file?
We can use either
head -2 file.dat | tail -1 or
cat file.dat | sed -n 2p > output.dat
sed -n 2p
3. Write a shell script that accept 7 numbers in loop?
Write a shell script that accept 7 numbers in loop,then make a sum of this numbers. Then count the numbers that are greater than 250 ?
4. How would you print just the 25th line in a file ?
send -n 25 p
cat filename.txt | cut -c 10-20
sed -n 25p file_name
cut -c 10-20 filename
small shell script that adds an extension ".New" to all the files in a directory
Code
- for i in *;
- do mv $i $i.New;
- done