Kuk Linux 2023
Q1(a):- Write atleast three types of shells and how to change shell.
1. Bourne Again Shell (bash)
- Bash is one of the most commonly used shells in Unix-like systems.
- It is an enhanced version of the original Bourne Shell (sh).
- Features include command-line editing, job control, and shell functions.
2. Z Shell (zsh)
- Zsh is known for its powerful features and customization options.
- It includes features from bash, ksh, and tcsh.
- Zsh has powerful scripting capabilities and built-in support for plugins.
3. Fish Shell (fish)
- Fish (Friendly Interactive Shell) is known for its user-friendly and interactive features.
- It has a clean syntax and offers powerful features out of the box.
- Features include autosuggestions, syntax highlighting, and web-based configuration.
Changing the Default Shell for a User
To change the default shell for your user, you can use thechsh
(change shell) command. Here are the steps:
1. Open Terminal:
Open your terminal application.
2. Check Available Shells:
View the list of available shells on your system by running:
cat /etc/shells
3.Change Shell:
Use the chsh command followed by the path of the new shell:
Use the chsh command followed by the path of the new shell:
chsh -s /path/to/shell
Replace
4. Verify the Change:
/path/to/shell
with the actual path to the shell you want to use (e.g., /bin/bash
, /usr/bin/zsh
).
4. Verify the Change:
Log out and log back in, or restart your terminal. Verify the change by checking the shell.
echo $SHELL
Q1(b):- Write a program to find largest of three numbers.
Bash Script to Find the Largest of Three Numbers
1. Create a new file
nano largest_of_three.sh
2. Add the following script:
#!/bin/bash
# Function to find the largest of three numbers
find_largest() {
if [ $1 -gt $2 ] && [ $1 -gt $3 ]; then
echo “The largest number is: $1”
elif [ $2 -gt $1 ] && [ $2 -gt $3 ]; then
echo “The largest number is: $2”
else
echo “The largest number is: $3”
fi
}
# Read three numbers from the user
read -p “Enter the first number: ” num1
read -p “Enter the second number: ” num2
read -p “Enter the third number: ” num3
# Call the function with the input numbers
find_largest $num1 $num2 $num3
3. Make the script executable:
chmod +x largest_of_three.sh
4. Run the script:
./largest_of_three.sh