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 4

< Previous Page
Question: Can you give some examples of few common Signals in Linux?
Answer: Please find below few common signals:
• SIGINT: This is the signal generated when a user presses Control-C to terminate the program from terminal.
• SIGALRM: This one is generated when a timer set by an alarm function goes off.
• SIGSTOP: This signal tells LINUX to pause a process to be resumed later.
• SIGCONT: This signal asks LINUX to resume the processed paused earlier.
• SIGABRT: This is generated when a process executes the abort function.
• SIGKILL: This one is sent to a process to cause it to terminate at once.

Question: Is it possible to use regular expressions in Bash scripts?
Answer: Regular expressions (regex) are implemented using the =~ operator, below please find some sample code:
 if [[ $inputvalue =~ [0-9]+ ]]
 then 
    echo "Input contains numbers"
 fi

Question: Can you use Arrays in Bash scripts?
Answer: Within Bash script one can create and use arrays in following way, point to remember that the array index is zero-based:
 names=(“John” “Scott″)  # Declare

 names[2]=“Michael”  # Add

 unset ‘names[1]’    # Remove

 echo "Hello ${names[0]}, how can I help you?"   # Access a particular record

 echo "Array length: ${#names[@]}"   # Get length

 for i in “${names[@]}”; do echo $i; # Print all records in an array

Question: How can you define STEP value in a FOR Loop within Bash script?
Answer: Bash (version 4.0+) provides inbuilt support for setting up a step value using {START..END..INCREMENT} syntax:
 #!/bin/bash
 for i in {0..10..2}
 do
   echo "Welcome $i times"
 done


< Previous Page