Top 50 Bash Scripting Interview Questions with Answers

Bash Scripting Interview Questions with Answers
  1. What does the “$” symbol represent in bash scripting?
    A) Comment
    B) Variable
    C) Function
    D) Command

Answer: B

  1. Which command is used to make a directory in bash scripting?
    A) cd
    B) ls
    C) mkdir
    D) touch

Answer: C

  1. What does the command “chmod” do in bash scripting?
    A) Changes ownership of a file
    B) Creates a new file
    C) Changes permissions of a file
    D) Deletes a file

Answer: C

  1. Which command is used to display the contents of a file in bash scripting?
    A) cat
    B) echo
    C) ls
    D) mkdir

Answer: A

  1. What is a shebang in bash scripting?
    A) A comment
    B) A variable
    C) A function
    D) A directive

Answer: D

  1. What is the purpose of an if statement in bash scripting?
    A) To create a loop
    B) To define a function
    C) To test a condition
    D) To display output

Answer: C

  1. Which command is used to remove a directory in bash scripting?
    A) rmdir
    B) rm
    C) mv
    D) ln

Answer: A

  1. What does the command “grep” do in bash scripting?
    A) Searches for a pattern in a file
    B) Creates a new file
    C) Displays the contents of a file
    D) Changes permissions of a file

Answer: A

  1. What is the purpose of a while loop in bash scripting?
    A) To create a loop
    B) To define a function
    C) To test a condition
    D) To display output

Answer: A

  1. How do you assign a value to a variable in bash scripting?
    A) Variable = value
    B) $Variable = value
    C) Variable : value
    D) $Variable : value

Answer: A

  1. Which command is used to move a file in bash scripting?
    A) cp
    B) rm
    C) mv
    D) ln

Answer: C

  1. What is the purpose of a for loop in bash scripting?
    A) To create a loop
    B) To define a function
    C) To test a condition
    D) To display output

Answer: A

  1. What does the command “echo” do in bash scripting?
    A) Searches for a pattern in a file
    B) Displays the contents of a file
    C) Changes permissions of a file
    D) Displays output

Answer: D

  1. Which command is used to copy a file in bash scripting?
    A) cp
    B) rm
    C) mv
    D) ln

Answer: A

  1. What is the purpose of a case statement in bash scripting?
    A) To test a condition
    B) To create a loop
    C) To define a function
    D) To display output

Answer: A

  1. What does the command “cd” do in bash scripting?
    A) Changes ownership of a file
    B) Creates a new file
    C) Changes to a different directory
    D) Deletes a file

Answer: C

  1. Which command is used to find the current working directory in bash scripting?
    A) pwd
    B) ls
    C) cd
    D) touch

Answer: A

  1. What is a function in bash scripting?
    A) A command that performs a specific task
    B) A variable that stores a value
    C) A conditional statement
    D) A loop

Answer: A

  1. What does the command “tee” do in bash scripting?
    A) Displays output
    B) Copies input to output
    C) Edits a file
    D) Moves a file

Answer: B

  1. What is the purpose of a do-while loop in bash scripting?
    A) To create a loop
    B) To define a function
    C) To test a condition
    D) To display output

Answer: A

  1. Which command is used to create a file in bash scripting?
    A) cp
    B) rm
    C) mv
    D) touch

Answer: D

  1. What does the command “sed” do in bash scripting?
    A) Searches for a pattern in a file
    B) Edits a file
    C) Displays the contents of a file
    D) Changes permissions of a file

Answer: B

  1. What is the difference between single and double quotes in bash scripting?
    A) Single quotes prevent variable expansion, double quotes don’t
    B) Double quotes prevent variable expansion, single quotes don’t
    C) There is no difference
    D) Both prevent variable expansion

Answer: A

  1. Which command is used to get the length of a string in bash scripting?
    A) strlen
    B) $length
    C) length
    D) expr length

Answer: D

  1. What does the command “wc” do in bash scripting?
    A) Edits a file
    B) Displays the contents of a file
    C) Counts the number of lines, words, and characters in a file
    D) Changes permissions of a file

Answer: C

  1. What is the purpose of the “shift” command in bash scripting?
    A) To delete variables
    B) To move variables to the left
    C) To move variables to the right
    D) To change variable values

Answer: B

  1. Which command is used to concatenate files in bash scripting?
    A) cp
    B) rm
    C) cat
    D) ln

Answer: C

  1. What is the purpose of the “export” command in bash scripting?
    A) To export variables to a new script
    B) To import variables from a script
    C) To delete variables
    D) To move variables to the left

Answer: A

  1. What does the “let” command do in bash scripting?
    A) Calculates the result of an expression
    B) Displays output
    C) Edits a file
    D) Moves a file

Answer: A

  1. What is a comment in bash scripting?
    A) A directive
    B) A variable
    C) A function
    D) Text that is ignored by the interpreter

Answer: D

  1. Which command is used to remove a file in bash scripting?
    A) mkdir
    B) rmdir
    C) rm
    D) ln

Answer: C

  1. What does the command “cut” do in bash scripting?
    A) Cuts a file into pieces
    B) Displays the contents of a file
    C) Edits a file
    D) Cuts out specific fields from a file

Answer: D

  1. What is the purpose of the “break” command in bash scripting?
    A) To exit a loop
    B) To enter a loop
    C) To continue to the next iteration of a loop
    D) To display output

Answer: A

  1. Which command is used to display the environment variables in bash scripting?
    A) printenv
    B) env
    C) set
    D) export

Answer: C

  1. What does the “continue” command do in bash scripting?
    A) Skips to the next iteration of a loop
    B) Exits a loop
    C) Enters a loop
    D) Displays output

Answer: A

  1. What is the purpose of the “read” command in bash scripting?
    A) Reads input from the user
    B) Displays output
    C) Edits a file
    D) Moves a file

Answer: A

  1. Which command is used to search for a file in bash scripting?
    A) find
    B) grep
    C) locate
    D) search

Answer: A

  1. What is the purpose of the “source” command in bash scripting?
    A) To execute a script within a script
    B) To import variables from a script
    C) To delete variables
    D) To move variables to the right

Answer: A

  1. Which command is used to compare two files in bash scripting?
    A) diff
    B) cmp
    C) comp
    D) compare

Answer: A

  1. What does the “declare” command do in bash scripting?
    A) Declares a variable
    B) Deletes a variable
    C) Moves a variable to the left
    D) Moves a variable to the right

Answer: A

  1. Which command is used to redirect the output of a command to a file in bash scripting?
    A) >
    B) <
    C) |
    D) &

Answer: A

  1. What is the purpose of the “sleep” command in bash scripting?
    A) To pause the script for a specified number of seconds
    B) To delete variables
    C) To move variables to the left
    D) To move variables to the right

Answer: A

  1. Which command is used to rename a file in bash scripting?
    A) mv
    B) cp
    C) ln
    D) rm

Answer: A

  1. What is the purpose of the “until” statement in bash scripting?
    A) To create a loop
    B) To test a condition
    C) To display output
    D) To define a function

Answer: A

  1. Which command is used to display the contents of a file backwards in bash scripting?
    A) cat
    B) tac
    C) bacy
    D) back

Answer: B

  1. What is the purpose of the “basename” command in bash scripting?
    A) To get the name of a file without the directory path
    B) To get the directory path of a file
    C) To get the length of a string
    D) To concatenate files

Answer: A

  1. Which command is used to display the top 10 lines of a file in bash scripting?
    A) head
    B) tail
    C) more
    D) less

Answer: A

  1. What is the purpose of the “cut” command in bash scripting?
    A) To cut out specific fields from a file
    B) To search for a pattern in a file
    C) To display the contents of a file
    D) To concatenate files

Answer: A

  1. Which command is used to sort the lines of a file in bash scripting?
    A) sort
    B) srt
    C) sor
    D) fsort

Answer: A

  1. What does the command “awk” do in bash scripting?
    A) Searches for a pattern in a file
    B) Edits a file
    C) Displays the contents of a file
    D) Analyzes and manipulates text files

Answer: D

Ashwani Kumar
Latest posts by Ashwani Kumar (see all)
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x