1. Verify different UNIX commands (syntax to use with options). 2. Write a shell program to add two numbers using command line. 3. Write a shell program to convert distance into me... 1. Verify different UNIX commands (syntax to use with options). 2. Write a shell program to add two numbers using command line. 3. Write a shell program to convert distance into meter, cm, and km. 4. Write a shell script to extract the data from the date command.
Understand the Problem
The question consists of multiple assignments related to UNIX commands and shell scripting. It requires verifying various UNIX commands, writing a shell program to add two numbers, converting distances, and extracting data from the date command.
Answer
1. Use 'man [command]' for help. 2. Add numbers: `sum=$(($1 + $2))`. 3. Convert distance: `$((cm/100000)) km`. 4. Date format: `date '+%A %B %d %T %Z %Y'`.
-
Use 'man [command]' or '[command] --help' for UNIX command options.
-
Shell program to add numbers:
#!/bin/bash
sum=$(($1 + $2))
echo "Sum is: $sum"
- Convert distance:
#!/bin/bash
read -p 'Enter distance in cm: ' cm
echo "$((cm/100000)) km $(((cm%100000)/100)) mt $((cm%100)) cm"
- Extract date:
date '+%A %B %d %T %Z %Y'
Answer for screen readers
-
Use 'man [command]' or '[command] --help' for UNIX command options.
-
Shell program to add numbers:
#!/bin/bash
sum=$(($1 + $2))
echo "Sum is: $sum"
- Convert distance:
#!/bin/bash
read -p 'Enter distance in cm: ' cm
echo "$((cm/100000)) km $(((cm%100000)/100)) mt $((cm%100)) cm"
- Extract date:
date '+%A %B %d %T %Z %Y'
More Information
These shell scripts demonstrate basic arithmetic, command line arguments, and formatting outputs based on command input.
Tips
Ensure numbers are passed correctly as arguments when running shell scripts. Remember variable expansion syntax.
Sources
- Shell script to add two numbers using command line arguments - log2base2.com
- Adding two numbers using expr - Unix & Linux Stack Exchange - unix.stackexchange.com
AI-generated content may contain errors. Please verify critical information