Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12K views4 pages

CSE (R13@II.B-Tech II-Sem) EXP-7: Output

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

CSE (R13@II.

B-Tech II-Sem) EXP-7

a) Write a shell script that computes the gross salary of a employee according to the
following rules:

I. If basic salary is < 1500 then HRA =10% of the basic and DA =90% of the
basic.

II. If basic salary is >=1500 then HRA =Rs500 and DA=98% of the basic

The basic salary is entered interactively through the key board.

b) Write a shell script that accepts two integers as its arguments and computers the value of
first number raised to the power of the second number.

A) Write a shell script that computes the gross salary of a employee according to the
following rules:
I. If basic salary is < 1500 then HRA =10% of the basic and DA =90% of the
basic.
II. If basic salary is >=1500 then HRA =Rs500 and DA=98% of the basic
The basic salary is entered interactively through the key board.
$ vi gsalary.sh
echo "enter the basic salary:"
read bsal
if [ $bsal -lt 1500 ]
then
gsal=$((bsal+((bsal/100)*10)+(bsal/100)*90))
echo "The gross salary : $gsal"
fi
if [ $bsal -ge 1500 ]
then
gsal=$(((bsal+500)+(bsal/100)*98))
echo "the gross salary : $gsal"
fi

Output :

$ sh gsalary.sh
enter the basic salary:
1200
The gross salary : 2400
$ sh gsalary.sh
enter the basic salary:
2400
the gross salary : 5252

Salary: When a person works for someone else or company, (s)he is then said to hold a job
and is called Employee . The person or the company he or she works for is called Employer.
Money that is paid is called as Salary or Income or Wage.

bphanikrishna.wordpress.com
FOSSLAB Page 1 of 4
CSE (R13@II.B-Tech II-Sem) EXP-7
The salary consists of following parts.

Basic Salary: As the name suggests, this forms the very basis of salary. This is the core of
salary, and many other components may be calculated based on this amount. It usually
depends on one’s grade within the company’s salary structure.It is a fixed part of one’s
compensation structure.

Allowance: It is the amount received by an individual paid by his/her employer in addition to


salary to meet some service requirements such as Dearness Allowance(DA), House Rent
Allowance (HRA), Leave Travel Assistance(LTA) , Lunch Allowance, Conveyance
Allowance , Children’s Education Allowance, City compensatory Allowance etc. Allowance
can be fully taxable, partly or non taxable. One can read Understanding the components of
your salary and their taxation for more details.

B) Write a shell script that accepts two integers as its arguments and computers the value
of first number raised to the power of the second number.
[CSESTAFF@localhost foss]$ cat pow.sh
echo "Enter the integer value :"
read int1
echo "Enter the power of that integer:"
read int2
pv=$int1
i=1
while [ $i -lt $int2 ]
do
pv=`expr $pv \* $int1`
i=`expr $i + 1 `
done
echo "The value of first number to the power of the second number :"
echo "$pv"

[CSESTAFF@localhost foss]$ sh pow.sh


Enter the integer value :
6
Enter the power of that integer:
3
The value of first number to the power of the second number :
216

bphanikrishna.wordpress.com
FOSSLAB Page 2 of 4
CSE (R13@II.B-Tech II-Sem) EXP-7

expr command:
Expr command performs arithmetic operations on integers. It can perform the four basic
arithmetic operations, as well as the modulus (remainder function).
$ expr 5 + 10
15
$ a=10 b=5
$ expr $a + $b
15
$ expr $a / $b
2
$ expr $a * $b
expr: syntax error
$ expr $a \* $b
50

Metacharacters
Metacharacters are a group of characters that have special meanings to the UNIX operating
system. Metacharacters can make many tasks easier by allowing you to redirect information
from one command to another or to a file, string multiple commands together on one line, or
have other effects on the commands they are issued in. The following table lists some of the
metacharacters for the Rutgers default shell (the T shell).
Metacharacter Description
UNIX interprets a space as a separator not as a character.
* A wild card character that matches any group of characters of any length,
allowing a user to specify a large group of items with a short string. For
example, to specify all the files that start with 'abc', you use abc*.
? A wild card character that matches any single character. Thus ls ??? lists
files in the current directory whose names are only three characters long,
while ls ???.* lists those files with a three letter main name and any
extension.
[..] A set of characters that can be matched. Thus ls [a-c]*.??? lists all files
that begin with a, b, or c and have a three letter extension and lpr
[ad]* prints all files that begin with a or d.
$ Indicates that the following text is the name of a shell (environment) variable
whose value is to be used.
| Separates commands to form a pipe (see redirection in "Intermediate Use Of
The UNIX Operating System").
< Redirect the standard input (see redirection in "Intermediate Use Of The
UNIX Operating System").
> Redirect the standard output (see redirection in "Intermediate Use Of The
UNIX Operating System") to replace current contents.
>> Redirect the standard output (see redirection in "Intermediate Use Of The

bphanikrishna.wordpress.com
FOSSLAB Page 3 of 4
CSE (R13@II.B-Tech II-Sem) EXP-7

Metacharacter Description
UNIX Operating System") to append to current contents.
>& Redirect the standard output and standard error (see redirection in
"Intermediate Use Of The UNIX Operating System") to replace current
contents.
>>& Redirect the standard output an standard error (see redirection in
"Intermediate Use Of The UNIX Operating System") to append to current
contents.
% Introduces a job name (see multitasking in "Intermediate Use Of The UNIX
Operating System").
& Place a process into the background (see multitasking in "Intermediate Use
Of The UNIX Operating System").
() Encloses a sequence of commands or pipes to be executed as a single
command.
! Precedes a history substitution (see "man history")
; Separates sequences of commands (or pipes) that are on one line.
&& Separates two sequences of commands or pipes the second of which is
executed only if the first succeeds.
|| Separates two sequences of commands or pipes the second of which is
executed only if the first fails.
\ Used to "quote" the following metacharacter so it is treated as a plain
character, as in \*.

bphanikrishna.wordpress.com
FOSSLAB Page 4 of 4

You might also like