0% found this document useful (0 votes)
45 views4 pages

Bash Scripts for Factorial and Arithmetic Operations

The document contains 3 questions asking to write Bash scripts and functions. Question 1 asks to write a function that returns the factorial of a passed integer. Question 2 asks to write a script that takes 2 integers, performs arithmetic operations on them, and writes the output to a file without overwriting previous runs. Question 3 asks to write a function that takes book information from a here-document, stores it in 6 variables, and writes the variable values to a file without overwriting previous runs.

Uploaded by

JUNAID -
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views4 pages

Bash Scripts for Factorial and Arithmetic Operations

The document contains 3 questions asking to write Bash scripts and functions. Question 1 asks to write a function that returns the factorial of a passed integer. Question 2 asks to write a script that takes 2 integers, performs arithmetic operations on them, and writes the output to a file without overwriting previous runs. Question 3 asks to write a function that takes book information from a here-document, stores it in 6 variables, and writes the variable values to a file without overwriting previous runs.

Uploaded by

JUNAID -
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Question no 01: [4 Marks]

Write a Bash Function which returns Factorial of an integer passed as an argument to the
script. Returned value must be captured and printed.
ANSWER:

Question no 02: [4 Marks]


Write a bash script to take two integers as arguments and apply all arithmetic operations on
them and then print the output on a file named “OUTPUT”.
NOTE: Every time you run the script the previous output must NOT be lost.

ANSWER:
Question no 03: [5 Marks]
You have to create Bash Function named BookInfo in the script which will take data from
HereDocument text. Six variables are declared in the function which will take data from user.

-ISBN,
-bookName,
-authorName,
-edition,
-publication
-price

Print all these variables output on a file name “ MyBooks”


NOTE: Every time you run the script the previous output must NOT be lost

ANSWER:

You might also like