Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Note: All shell script files are created with extension "sh" (eg. filename.sh) u
sing vim editor (eg. vi filename.sh) and executed using sh command (eg. sh filen
ame.sh)
Ans 1.
who
Ans 2.
Shell Script: (saved as second.sh)
echo HELLO WORLD
C Program: (saved as second.c)
#include <stdio.h>
int main()
{
printf("\nHELLO WORLD");
}
gcc second.c
time second.sh;time ./a.out
Ans 3.
a.
echo "Enter a File name"
read f
if [ -f $f ]
then
echo "FILE"
elif [ -d $f ]
then
echo "DIRECTORY"
else
echo "NOT FOUND"
fi
b.
echo "Enter a file name: "
read a
while [ $a != 0 ]
do
a=$(echo $a | tr 'a-z' 'A-Z')
echo $a
echo "Enter a file name: "
read a
done
c.
2262 = PID (Process Identifier)
ps -p 2662 -o etime
Ans 4.
a.
echo "Enter the Filename"
read fname
echo "Enter the Starting Line Number"
read s
echo "Enter the Ending Line Number"
read n
sed -n $s,$n\p $fname
b.
echo
read
echo
read
grep
Ans 5.
echo "Enter numnber : "
read n
rem=$(( $n % 2 ))
if [ $rem -eq 0 ]
then
echo "$n is even number"
else
echo "$n is odd number"
fi
Ans 6.
my_string=abc
substring=ab
if [ "${my_string/$substring}" = "$my_string" ] ; then
echo "${substring} is not in ${my_string}"
else
echo "${substring} was found in ${my_string}"
fi
Ans 7.
echo "Enter First File Name"
read file1
echo "Enter Second File Name"
read file2
if ( cmp $file1 $file2 )
then
echo "Files are same"
rm $file2
echo "Second File Deleted"
else
echo "Files are not same"
fi
Ans 8.
echo "Enter a Filename"
read file
echo "Enter a Word"
read word
grep -wo $word $file | wc | awk '{print $1}'
Ans 9.
a.
echo "Enter a String"
read string
echo "Enter Starting Index"
read s
echo "Enter Ending Index"
read e
substring=`echo $string | cut -c$s-$e`
echo $substring
b.
echo "Enter a String"
read string
echo "The length of String Entered is ${#string}"
Ans 10.
ps aux
Ans 11.
chown username filename/process ID