https://www.youtube.com/watch?v=9X7G3uhnP6k&list=WL&index=45&t=1s
What is a shell?
Ans:
What is shell scripting?
Ans:
How to tell which shell you are in or running?
Ans: $0
Different types of commonly used shells on Linux systems?
Ans:
How to run/execute a script?
After executing a shell script, how to terminate it?
Ans:
What is the default login shell? How to change it?
Ans: CHSH
What is the purpose of the shebang line?
Ans: (#!/bin/bash) To tell the Linux OS which interpreter to use to parse the rest of the file.
Comments in a shell script?
Ans:
Multi-line comments in a shell script?
Ans:
Which commands are used to print output in bash?
Ans: echo
Which exit status indicates a successful execution for a bash script?
Ans: 0
How to make any variable unchangeable or readonly?
Ans: using 'readonly' readonly variable_name=value
How to find out how many arguments passed to a script?
Ans: using $#
Which of the following are used to end a case statement in a Bash script?
Ans: esac
How to check a directory exists or not using bash?
Ans: [!-d /directory]
In what ways, the shell script can check if the user executing it is a 'root' user or not?
Ans: We can use against the value of UID shell variable UID of root user is always 0
How will you automate your script to run/execute at a given time?
Ans: Using crontab or at commands
How will you find total shells available in your system?
Ans: cat /etc/shells What is the use of ? gives you current process ID
In a Bash shell script, if you want to restart the loop at the next iteration before the loop completes, use the ____ statement.
Ans: Continue
In a Bash script, which of the following tests if the value stored in the variable "MON" is equal to the string of "June"?
Ans: [[${MON}="June"]]
You are writing a Bash script and want to test if the "/tmp/out.txt" exists and can be read by the user running the script. Which of the following conditionals would you use?
Ans: [-f/tmp/out.txt]
In a Bash shell script, which of the following operators is used to test if 2 strings are equal?
Ans: =
Which of the following will take the output of the "hostname" command and store it in the variable named "HOST"?
Ans: HOST=$(hostname)
Which of the variable is valid to use in shell script?
Ans: var@ 2.var-1 3.1var 4.VAR 5.$VAR Ans: 4
Differentiate between $@ and $*.
Ans: $* - consider all arguments as single entry $@ - consider all arguments as seperate entry
Example: for i in "$@"
How to redirect and append both stdout and stderr to a file with Bash?
Ans: file.txt 2>&1
A while loop is a loop that repeats a series of commands for as long as a given condition is ___
Ans: True
Difference between if-then and case statement?
Ans: if-then looks for the matching criteria and case gives you the list of options to choose from
In what ways, shell script get input values from a user or terminal?
Ans: a. By reading command: read -p "Your name" name b. By parametets: ./script param1 param2
How to check whether a link is a hard one or a soft link?
Ans: We can use -h and -L operators of the test command to check whether a link is hard or soft (symbolic link)
How to debug a shell script?
Ans: By setting -x in the script we can enable deubugging.
To run ascrot, what typpe of permission ascript should have?
Ans: Executable permisssion need to be provided to script. We can use 'chmod' command for this.
Is it possible to run multiple scripts at a time? If yes then how?
Ans: To run multiple scripts at a time, we can invoke name of the scripts in an another script.
Like script1, script2 can be used in script3
What are Metacharacters in a shell?
Ans: Special character which provide information about other character. Example:*
What are loops in shell? What are the types?
Ans: Loops are used to repeatedly run a portion of scipt for a given no, of repetition or until condition is met
for loop, while loop, until loop
Which of the following are used to end a if-else statement in a Bash script?
Ans: done 2. fi 3. exit 4.end Ans: fi
How to define an infinite loop in a Bash script?
Ans: while true
How to use expressions in a script?
Ans: We can use 'let' Example: let i++
How to get name of the current script and print within a script?
Ans: We can use ${0} within our script which will print the name of our current running script
What are functions in shell scripting?
Ans: Block of code which perform some task and run when it is called.
Can be reuse many times in our program which lessen our lines of code.
We can pass arguments to the functions.
How to make a basic function in shell scripting?
Ans: function myfun{ echo "Hello" }
myfun(){}
How to print a random integer in a shell scripting?
Ans: We can use built in bash variable called RANDOM which will print random no. between 0-32767
In a shell script, what will you do if you don't want to print the output of a command on the terminal and also in a file?
Ans: We can redirect the output to /dev/null
What can be used to create delay between 2 executions?
Ans: We can use sleep command like: sleep 1s sleep 1m
How to stop a script in based on a given condition? Which keyword can be used to stop a script.
Ans: Using exit command
What is the use of logger in a shell scripting?
Ans: It is used to maintain logs for your script. We can find the logs under /var/logs/messages
What is the use exit status $? in a shell scripting?
How to check whether a link is a hard one or a soft link? We can use -h and -L operators of the test command to check whether a link is hard or soft (symbolic link)
To run a script, what type of permission a script should have and how will you provide it?
Executable permission need to be provided to script. We can use 'chmod' command for this.
Is it possible to run multiple scripts at a time? If yes then how?
To run multiple scripts at a time, wr can invoke name of the scipts in an another script. Like script1, script2 can be used in script3
What are metacharacters in a shell?
Special character which provide inforamtion about other character eg: *
What are loops in shell? what are the types?
Loops are used to repeatedly run a portion of script for a given no, of repetition or until condition is met.
for loop, while loop, until loop
With the help of Maven, Gradle or ANT we can create .jar, .war and .ear files
Divisible by 3, divisible by 5, not 3*5=15
for i in {1..100};do
if ([
expr $i % 3
== 0 ] || [expre $i % 5
== 0]) && [expr $i %15
!= 0]; then echo $i fi; doneHow to check current default permission?
Ans: unmask Permsisson will be (Permission = 0777 - 0022 = 0755 unmask -S Syntax of unmask (unmask u+rw,g+w,o+wx)
To change default permission permanenetly Add the permission in .bashrc file.
What is SSH?
Ans: SSH is also command in Linux. It is used to access an another Linux server or accessing a Linux server from a terminal Syntax: ssh user_name@host(IP/Domain_name)
How to use? To use SSH, ssh service must be installed on Linux server. You can check using (rpm -qa | grep ssh) or check the file (/etc/ssh/sshd_config)
If not already installed then install below two (install openssh-clients openssh-server and now enable the ssh or check if it is enabled using (systemctl status sshd)
Examples:
Access Linux server using Putty
Access a Linux server from another server
Permissions: (rwx levels) u - yourself g - group in which user belongs to o - others a - all
What are wildcards? (A wildcard is a character that can be used as a substitute for any of a class of characters in a search.
- zero or more characters ? - single character [] - range of character
List some of the commonly used shell commands?
Ans: ls, cp, mv, mkdir, touch, vim, grep, netcat route
Write a simple shell script to list all processes
Write a script to print only errors from a remote log
Ans: curl pipe and grep
Write a shell script to print numbers divided by 3 & 5 and not 15
Ans: Divisble by 3, Divisible by 5, And not by 15
for i in {1..100}; do
if ([
expr $i % 3
== 0 ] || [expr $i % 5
\==0]) && [`expr &i % 15` !=0];then
echo $i
fi;
done
How do you debug a shell script?
Ans: set -x
What is crontab in Linux? Can you provide an example of usage?
Ans: Crontab -> Linux admin; Report -> node health
How to open a read only file?
Ans: vim -r test.txt