Reference Page: SQL|PowerShell|Bash|Docker

Bash-Shell Links : Learn     Interview Questions     Software IDE Bash-Shell Jobs : Indeed.com     ZipRecruiter.com     Monster.com

Bash (Shell) Interview Questions - Page 1

Next Page >
Question: What is a Shell??
Answer: Shell is a CLI (command-line-interpreter) for user input and kernel of the environment designed to execute commands, scripts and programs. When input commands are entered through keyboard, the shell communicates with kernel and executes these commands to display the output. So Shell basically translates user-entered commands into a kernel understandable language.

Question: Can you specify few common usage of shell scripts?
Answer: Following are few common usage:
• Monitoring the system.
• Adding new functions.
• Routine backups.
• Automating daily tasks.

Question: What are few limitations of shell scripting?
Answer: Below one can find certain limitations:
• Errors are costly and debugging is difficult.
• Single error can alter entire system.
• Complex tasks are not suitable.
• Provides minimal data structures.
• New process launched with every shell command.

Question: How one can pass arguments in shell script?
Answer: One can pass arguments to a shell script by listing them after name of the script:
./my_script.sh arg1 arg2

Question: How one can access arguments within a shell script?
Answer: One can access arguments within the script with a dollar sign and a number that indicates the argument’s order:
$1 # =arg1
$2 # =arg2

Question: What is the use of $# in a shell script?
Answer: The symbol $# is a global variable within the shell script that gives the count of the arguments passed to it.

Question: How can one debug a Bash script?
Answer: Debugging can be done using ‘-x’ option while running script. This way it prints each command before execution allowing you tracing the flow.

Also ‘set -e’ can be used, this allows script to exit immediately if any command exits with non-zero status. This is helpful to catch any error early before causing further issues.

Besides those, using ‘trap’ command errors can be handled. The ‘trap’ command can capture line-number ($LINENO) and Error message (ERR) with a program.

Next Page >