shell_script-programs(1)
shell_script-programs(1)
read NUM1 # Read the user input from Standard Input and store in Variable NUM1
read NUM2
2) Write a Shell script program to print today’s date, calendar & type of shell.
#! /bin/bash
3) Write a Shell script program to print path and current working directory.
CONSTANT_VAR="New Value"
5) Write a shell script program to print number from 1 to 10 using until loop
#!/bin/bash
counter=1
echo $counter
done
Until loop
#!/bin/bash #
num=1
do
echo $num
num=$((num + 1))
done
6) Write a shell script program to print the Fibonacci series of the term.
#!/bin/bash
# Prompt the user to enter the number of terms for the Fibonacci series
if [ $n -le 0 ]; then
echo "Please enter a positive integer."
fi
do
echo -n "$a " # -n ensures the numbers are printed on the same line
done
echo
7) Write a shell script program to print numbers from 1 to 100 using while loop.
#!/bin/bash
num=1
echo $num
done
#!/bin/bash
# Validate input
exit 1
fi
# Initialize variables
factorial=1
i=1
factorial=$((factorial * i))
i=$((i + 1))
done
9) Write a shell script that displays a list of all the files in the current directory
#!/bin/bash
# Display a message
ls -l
10) Write a shell script called hello which outputs the following:
• your username
• who is logged on
#!/bin/bash
whoami
echo "*********"
date
echo "*********"
echo "*********"
11) Write the shell script program to demonstrate the working of command line arguments
such as $0, $#, $* & $?.
#!/bin/bash
ls # Run `ls`
12) Write a shell script to echo the string length of the given string as argument.
#!/bin/bash
exit 1
fi
input_string="$1"
string_length=${#input_string}
#!/bin/bash
if [ $# -ne 3 ]; then
exit 1
fi
file1="$1"
file2="$2"
file3="$3"
output_file="combined_file.txt"
exit 1
fi
# Optionally, display the content of the combined file (uncomment the line below)
# cat "$output_file"
14) Write a shell script program to print numbers from 1 to 100 in reverse order using for
loop
#!/bin/bash
do
echo $i
done
15) Write shell script program to print even numbers from 1 to 100 using for loop
16) Write shell script program to print environment variables / predefined variables.