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 3

< Previous Page              Next Page >
Question: How the exit statuses are used in Bash scripts?
Answer: The exit status in Bash script is used for error handling and to decide the control flow. These are numerical codes returned on command completion and indicate success (0) or failure (non-zero).

The logic part of scripts utilize these to make a decision based on the returned status.

Question: Can you handle events in Bash script?
Answer: Software interrupts, called Signals are used in Bash programs to handle events.
Signals are handled in Bash using ‘trap’ command.

Question: How many types of Signals are there in Bash?
Answer: Two types of signals are there:
• Synchronous: Occurs within process due to code execution.
• Asynchronous: These are the signals that come from outside of the process

Question: Can you create functions in Bash script??
Answer: In Bash scripting, function can be defined using optional ‘function’ keyword.

Below one can find examples of sample functions and how to call them.
 function myfunction1() {
    # code goes here
 }

 myfunction2() {
    # code goes here
 }

 # Call the functions
 myfunction1
 myfunction2

Question: How can you read an user input using Bash script?
Answer: User input can be captured using ‘read’ command.
Below you can find a simple example:
 #!/bin/bash
 echo "Kindly enter your first name:"
 read name
 echo "Hi $name, how can I help you?"


< Previous Page Next Page >