Professional Documents
Culture Documents
Experiment No.:8
Aim: Execution of advanced programs of shell scripting.
a. Write a shell script to implement menu-driven calculator using case statement.
b. Write a shell script to compare two strings.
c. Write a shell script to read and check if the directory / file exists or not, if not make
the directory / file.
Output:
a. Write a shell script to implement menu-driven calculator using case statement.
When writing Bash scripts you will often need to compare two strings to check if they are
equal or not. Two strings are equal when they have the same length and contain the same
sequence of characters.
string1 = string2 and string1 == string2 - The equality operator returns true if the
operands are equal.
Use the = operator with the test [ command.
Use the == operator with the [[ command for pattern matching.
string1 != string2 - The inequality operator returns true if the operands are not equal.
string1 =~ regex- The regex operator returns true if the left operand matches the
extended regular expression on the right.
string1 > string2 - The greater than operator returns true if the left operand is greater
than the right sorted by lexicographical (alphabetical) order.
string1 < string2 - The less than operator returns true if the right operand is greater
than the right sorted by lexicographical (alphabetical) order.
-z string - True if the string length is zero.
-n string - True if the string length is non-zero.
3. When working with Bash and shell scripting, you might need to check whether a
directory or a file exists or not on your filesystem.
Based on this condition, you can exit the script or display a warning message for the end user
for example.
In order to check whether a file or a directory exists with Bash, you are going to use “Bash
tests”.