Shell Scripting Quiz (Set 16) Shell Scripting (Set 6) 1 / 10 In a shell script, how do you perform arithmetic operations on variables? add(num1, num2) $[num1 + num2] $((num1 + num2)) $(num1 + num2) 2 / 10 What is the purpose of the 'pgrep' command in a shell script? Searches for processes by name Kills processes Prints process information Lists running programs 3 / 10 In a shell script, how do you find the index of an element in an array? ${array[@]/element} ${array[element]} ${array[@]} ${!array[@]} 4 / 10 What is the purpose of the 'eval' command in a shell script? Evaluates arithmetic expressions Evaluates shell commands from a string Evaluates regular expressions Evaluates command-line arguments 5 / 10 In a shell script, how do you compare two integers for equality? if [ $num1 -eq $num2 ]; then if [ num1 == num2 ]; then if [ $num1 == $num2 ]; then if [ num1 -eq num2 ]; then 6 / 10 What is the purpose of the 'env' command in a shell script? Executes a command in a new environment Creates a new environment variable Exports variables to subshells Displays environment variables 7 / 10 Which operator is used for command grouping in a shell script? ${ } ( ) $( ) [ ] 8 / 10 What is the purpose of the 'basename' command in a shell script? Extracts the directory from a path Prints the working directory Deletes a file Extracts the filename from a path 9 / 10 In a shell script, how do you read input from a file line by line? for line in file.txt; do read line from file.txt; do while read line; do foreach line in file.txt; do 10 / 10 What is the purpose of the 'trap' command in a shell script? Catches errors in the script Sets up actions to be taken when signals are received Defines user-defined functions Creates temporary variables Your score isThe average score is 0% 0% Restart quiz