Shell Script Interview Questions and Answers
x=`cut -f4 ram.txt`
y=`cut -f5 krish.txt`
z=`expr x-y`
if (z==5)
then echo 5
else
w= `expr 5*z`
echo $w
fi
you can use CYGWIN which can be installed on various Windows platform.
echo enter filename
read file
for n in `cat $file`
do
i=`expr $n % 2`
if [ $i -eq 0 ]
then
echo $n>>even.txt
else
echo $n>>odd.txt
fi
done
$ java weblogic.version -verbose
(OR)
$ java weblogic.utils.Versions
(OR)
java weblogic.Admin -url ManagedHost:8001 -username weblogic
-password weblogic VERSION
for var in `ls -1S` === -S sort the file primary key as
size of the file and -1 column o/p
do
if [[ $i -eq 5 ]]
then
break;
fi
print $var
let i=i+1;
done
Same code can be used for time and ls command option will be
ls -1t
while running the script using this “./” script run from
curent location we have to give executable permision to the
script file
By default file contains 644 permissions there is no
execute permission while running it shows error
use `chmod` to give execute permission and run
where as “sh” it runs the script with the help of default
shell
Yes..:)
just open unix prompt
vi ” ” or vi “ab cd”
echo “jagadeeb”
:wq
just give permission :)like
chmod 777 ” ” or chmod 777 “ab cd”
and run that like
./” ” or ./”ab cd”
out put like
jagadeeb
jagadeeb@gmail.com
Sorry Sudhir,
Your syntax is wrong.It should be
paste file1 file2|cut -d ” ” -f2,3,4
But this command is n’t providing the correct result.
Piz try another.
awk ‘NR % 50 == 0’ print
read line;
echo $line | awk ‘{ for ( i = NF; i > 0; i–) print $i}’ |
tr “n” ” “
cho “Enter Choice”
read num
case $num in
1) echo `date`
;;
2) ls
;;
3) who
;;
*) echo “Wrong option press 1 2 3 only”
;;
esac
write code like this :
#!/bin/bash
echo “My script2 call”
/bin/bash ./script2.sh [ or /bin/ksh ./script2.sh ]
It will run ….. enjoy !!!!!!
1.Data Abstraction
2.Data Encapsulation
3.Polymorphism
4.Inheritance
$ ls -al | sort -n -k5
The -n in my example means “sort numerically”, and the -k5
option means to key off of column five. Like other Unix
commands, these options can be combined and shortened, like
this:
$ ls -al | sort -nk5
echo ‘obase=16 ; ibase =2 ; binaryno’|bc #print hexadecimal
echo ‘obase=2 ; ibase=16; hexa no’|bc #print binary no
type “r”. It will execute the last executed command
follow sunitabh Das unix book
It is in /var/spool/cron/crontabs
Each user have seperate file in this location. moreover
normal user cannot view this file, only root user can
access.
login to the remote server using ssh and use top -d1 command
, it will show the load average on the server.
SH refers to Bourne Shell, which is someway the reference Shell to a lot of other Shells, and defintaly to the Bash Shell, which literally is : Bourne Again Shell. By this time and date (2015), Bash is to be preferred over Bourne, and Bourne is supposed to be limited too much … but, still used a lot. Obviously, in a technical way, there’s a lot of interesting commands that work only with Bash, not with Bourne (and presumingly, never the other way round). So, bottom line : Bourne is limited but very compatible, Bash is better but slightly limited. The latter largely depends on environments.