Bash MCQ: Bash Multiple Choice Questions and Answers

Bash MCQ with answers and explanations for placement tests and job interviews. These solved Bash MCQs are useful for the campus placement for all freshers including Engineering Students, MCA students, Computer and IT Engineers, etc.

Our Bash MCQ (Bash Multiple Choice Questions ) focuses on various parts of the Bash shell and command language its concept. It will be useful for anyone learning Bash language Basics, Essentials, and/or Fundamentals. We will regularly update the quiz and most interesting thing is that questions come in a random sequence. So every time you will feel new questions.

If you want to learn Bash command Language in detail you can follow these courses created by industry experts, Trial of some courses is free.

Guideline of Bash MCQ:

This Bash MCQ is intended for checking your Bash framework knowledge. It takes 1 hour to pass the Bash MCQ. If you don’t finish the Bash MCQ within the mentioned time, all the unanswered questions will count as wrong. You can miss the questions by clicking the “Next” button and return to the previous questions by the “Previous” button. Every unanswered question will count as wrong. MCQ on Bash has features of randomization which feel you a new question set at every attempt.

In this Bash Quiz, we have also implemented a feature that not allowed the user to see the next question or finish the Bash quiz without attempting the current Bash MCQ.

0 votes, 0 avg

You have 1 hours to take the BASH MCQs

Your time has been Over.


Bash MCQ

BASH MCQ

Bash MCQ:  Bash Multiple Choice Questions and Answers

1 / 53

What does this bash statement do?

(( $a == $b ))
echo $?

 

2 / 53

Which command is being run in this script to check if file.txt exists?

if [ -f file.txt ]; then
    echo "file.txt exists"
fi

 

3 / 53

What does the asterisk represent in this statement?

<em>#!/usr/bin/env bash</em>
case $num in
  1)
  echo "one"
  ; ;
  2)
  echo "two"
  ; ;
  *)
  echo "a mystery"
  ; ;
esac

 

4 / 53

What does this script accomplish?

#!/bin/bash
declare -A ARRAY=([user1]=bob [user2]=ted [user3]=sally)
KEYS=(${!ARRAY[@]})

for (( i=0; $i < ${#ARRAY[@]}; i+=1 ));do
        echo ${KEYS[$i]} - ${ARRAY[${KEYS[$i]}]}
done

 

5 / 53

Which statement checks whether the variable num is greater than five?

6 / 53

When used from within a script, which variable contains the name of the script?

7 / 53

What does the + signify at the end of the 10-digit file permissions on data.txt?

ls -l
-rwx------+ 1 user1 u1 0 Oct 1 10:00 data.txt

 

8 / 53

How would you find the last copy command run in your history?

9 / 53

The **\_\_** keyword pauses the script to get input from standard input.

10 / 53

Assuming that user1 existed, what would be the result of this command string?

awk -F: '/user1/{print $1 "-" $3 "-" $6}' /etc/passwd

 

11 / 53

Given the listed permissions on data.txt is it possible that user2 could have read, write, and execute permissions on data.txt?

$ ls -l
total 0
-rwx------+ 1 user1 user1 0 Oct 27 10:54 data.txt

 

12 / 53

If script.sh is run in the current directory, it will fail. Why?

$ ls -1
Beach photo1.jpg
Photo1.jpg
Photo2.jpg
Script.sh

$ cat script.sh
for i in $(ls *.jpg); do
  mv $i ${i}.bak
done

 

13 / 53

What is wrong with this script?

#!/bin/bash
read -p "Enter your pet type." PET
if [ $PET = dog ] ;then
    echo "You have a dog"
fi

 

14 / 53

In Bash, what does the comment below do?

cd -

 

15 / 53

What is the output of this code?

VAR="/var/www/html/website.com/html/"
echo "${VAR#*/html}"

 

16 / 53

What is the keyboard shortcut to call up the Bash history search as shown below?

(reverse-i-search)

 

17 / 53

To permanently remove empty lines from a file called textfile, which command could you use?

18 / 53

Which variable would you check to verify that the last command executed successfully?

19 / 53

What is the output of this script?

#!/bin/bash
fname=john
john=thomas
echo ${!fname}

 

20 / 53

Which file allows you to save modifications to the shell environment across sessions?

21 / 53

What will be in out.txt?

ls nonexistentfile | grep "No such file" > out.txt

 

22 / 53

If prompted for text at the standard input, you can tell the command you're done entering text with what key combination?

23 / 53

In order to write a script that iterates through the files in a directory, which of the following could you use?

24 / 53

What would be in out.txt?

cat < in.txt > out.txt

 

25 / 53

What happens if you use the "set -e" in a Bash script?

26 / 53

What do you use in a case statement to tell Bash that you're done with a specific test?

27 / 53

How does the SUID or setuid affect executable commands?

28 / 53

For the script to print "Is numeric" on screen, what would the user have to enter when prompted?

#!/bin/bash
read -p "Enter text " var
if [[ "$var" =~ "^[0-9]+$" ]];then
    echo "Is numeric"
else
    echo "Is not numeric"
fi

 

29 / 53

How could you get a list of all .html files in your tree?

30 / 53

What is the difference between the $@ and $* variables?

31 / 53

What does this command do?

cat > notes -

 

32 / 53

What is the result of this script?

txt=Penguins
[[ $txt =~ [a-z]{8} ]]; echo $?

 

33 / 53

Using "awk", what would the output of this command string be?

echo "1 2 3" | awk '{for (i=1; i<=NF; i++) s=s+$i};END {print s}'

 

34 / 53

What line of Bash script probably produced the output shown below?

The date is: Sun Mar 24 12:30:06 CST 2019!

 

35 / 53

Which arithmetic expression will give the most precise answer?

36 / 53

Using Bash extended globbing, what will be the output of this command?

$ ls -l
apple
banana
bananapple
banapple
pineapple
strawberry
$ shopt -s extglob
$ ls -l @(ba*(na)|a+(p)le)

 

37 / 53

What is the output of:

VAR="This old man came rolling"
echo "\${VAR//man/rolling}"

 

38 / 53

What happens if you use the "set -e" in a Bash script?

39 / 53

If file.sql holds SQL statements to be executed, what will be in file.txt?

mysql < file.sql > file.txt

 

40 / 53

What will be the difference between the output on the screen and the contents of out.txt

mysql < file.sql > out.txt

 

41 / 53

To run a copy command in a subshell, which syntax would you use?

42 / 53

How would you change your Bash shell prompt to the following?

HAL>

 

43 / 53

In order to extract text from the first column of file called textfile, which command would you use?

44 / 53

When executing a command and passing the output of that command to another command, which character allows you to chain these commands together?

45 / 53

Suppose your current working directory is your home directory. How could you run the script demo.sh that is located in your home directory? Find three correct answers.

A. /home/demo.sh
B. ./demo.sh
C. ~/demo.sh
D. bash /home/demo.sh
E. bash demo.sh

 

46 / 53

What will be the output of this script?

#!/bin/bash
Linux=('Debian' 'Redhat' 'Ubuntu' 'Android' 'Fedora' 'Suse')
x=3

Linux=(${Linux[@]:0:$x} ${Linux[@]:$(($x + 1))})
echo "${Linux[@]}"

 

47 / 53

Which of the three methods will copy the directory named "photo dir" recursively from the user's home directory to /backups?

cp -R "~/photo dir" /backups #method1
cp -R ~"/photo dir" /backups #method2
cp -R ~/"photo dir" /backups #method3

 

48 / 53

The command below will search the root filesystem for files named "finance.db". In this context, what information is being sent to /dev/null?

find / -name "finance.db" 1>results.txt 2>/dev/null

 

49 / 53

What Bash script will correctly create these files?

50 / 53

What file would match the code below?

ls Hello[[.vertical-line.]]World

 

51 / 53

In the script shown below, what is a greeting?

<em>#!/usr/bin/env bash</em>
greeting="Hello"
echo $greeting, everybody!

 

52 / 53

In order for a Bash script to be executed like an OS command, it should start with a shebang line. What does this look like?

53 / 53

How can you gather history together for multiple terminals?

Your score is

The average score is 0%

0%

Recommended Articles for you: