Shell Script Quiz Questions With Answers

Reviewed by Samy Boulos
Samy Boulos, MSc (Computer Science) |
Data Engineer
Review Board Member
Samy Boulos is an experienced Technology Consultant with a diverse 25-year career encompassing software development, data migration, integration, technical support, and cloud computing. He leverages his technical expertise and strategic mindset to solve complex IT challenges, delivering efficient and innovative solutions to clients.
, MSc (Computer Science)
Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By 21Centurians
2
21Centurians
Community Contributor
Quizzes Created: 1 | Total Attempts: 10,656
Questions: 22 | Attempts: 10,656

SettingsSettingsSettings
Shell Script Quiz Questions With Answers - Quiz

Are you familiar with Unix programming and shell scripting? Put your skills to the test with our engaging shell script quiz, featuring questions and answers on essential concepts in this topic. Shell scripting is a powerful, open-source programming method designed to be executed by the Unix/Linux shell. It allows users to automate tasks by writing scripts that direct the shell to perform a sequence of operations, such as file manipulation, program execution, and text processing.

Shell scripting is widely used for automating repetitive tasks, managing system administration, and simplifying complex operations. If you're looking to deepen your understanding of Read moreUnix programming and shell scripting or simply want to test your current knowledge, this quiz is the perfect place to start. Dive in now and see how much you know about the world of shell scripting!


Shell Script Questions and Answers

  • 1. 

    How can you append the output of a command to a file?

    • A.

      Command > file

    • B.

      Command >> file

    • C.

      Command <> file

    • D.

      Command < file

    Correct Answer
    B. Command >> file
    Explanation
    To append the output of a command to a file, you can use the "command >> file" syntax. The double greater than sign (>>) is used to redirect and append the output of the command to the specified file. This means that the output will be added to the end of the file without overwriting any existing content.

    Rate this question:

  • 2. 

    With what command you can see what folder you are in?

    • A.

      Whereami

    • B.

      Place

    • C.

      Map

    • D.

      Pwd

    Correct Answer
    D. Pwd
    Explanation
    The command "pwd" stands for "print working directory" and is used to display the current directory or folder that the user is in. This command is commonly used in command line interfaces to keep track of the user's location within the file system. By typing "pwd" and pressing enter, the user can see the full path of the current directory, which helps in navigating and locating files and folders.

    Rate this question:

  • 3. 

    How do you delete a file?

    • A.

      Rm filename

    • B.

      Dl filename

    • C.

      Touch filename

    • D.

      Less filename

    Correct Answer
    A. Rm filename
    Explanation
    The correct answer is "rm filename". The "rm" command in Unix/Linux is used to remove or delete files and directories. By using "rm" followed by the name of the file, you can delete the specified file.

    Rate this question:

  • 4. 

    How do you get all files with on the 3rd place an r, g or i?

    • A.

      Ls ?3[rgi]*

    • B.

      Ls *[rgi]*

    • C.

      Ls [..i*]

    • D.

      Ls ??[rgi]*

    Correct Answer
    D. Ls ??[rgi]*
    Explanation
    The correct answer is "ls ??[rgi]*". This answer uses the "?" wildcard to represent any single character and the "[rgi]" to match the characters 'r', 'g', or 'i'. Therefore, this command will list all files with any two characters followed by either 'r', 'g', or 'i'.

    Rate this question:

  • 5. 

    What command do you have to use to go to the parent directory?

    • A.

      Cd -

    • B.

      Cd /up

    • C.

      Cd ~

    • D.

      Cd ..

    Correct Answer
    D. Cd ..
    Explanation
    The correct answer is "cd ..". This command is used to go to the parent directory in the file system. The ".." represents the parent directory, allowing the user to navigate up one level in the directory structure.

    Rate this question:

  • 6. 

    With what command you can see your user name?

    • A.

      Pwd

    • B.

      I

    • C.

      Whoami

    • D.

      Me

    Correct Answer
    C. Whoami
    Explanation
    The correct answer is "whoami". The "whoami" command is used to display the username of the current user in a Unix-like operating system. It is a simple and straightforward way to quickly see the username associated with the current session.

    Rate this question:

  • 7. 

    With what can you stop a process?

    • A.

      Kill

    • B.

      Delete

    • C.

      Stop

    • D.

      Shutdown

    Correct Answer
    A. Kill
    Explanation
    The correct answer is "Kill." In computing, the "kill" command is used to terminate or stop a running process. It sends a signal to the process, instructing it to stop execution. This signal can be used to gracefully shut down a process or forcefully terminate it, depending on the specific use case. The other options listed, such as "Delete," "Stop," and "Shutdown," do not typically refer to stopping a process but rather involve other actions such as removing files, halting a system, or shutting down a computer.

    Rate this question:

  • 8. 

    What does the command ls do?

    • A.

      Shows a calendar

    • B.

      Display of files and folders, present in the folder where you are

    • C.

      Opening a file

    • D.

      Display of the contents of a file

    Correct Answer
    B. Display of files and folders, present in the folder where you are
    Explanation
    The command "ls" is used in the command line interface to list the files and folders present in the current directory. It does not show a calendar, open a file, or display the contents of a file.

    Rate this question:

  • 9. 

    What command is used to forward errors to a file?

    • A.

      2> /dev/null

    • B.

      &> filename

    • C.

      1> filename

    • D.

      2> filename

    Correct Answer
    D. 2> filename
    Explanation
    The command "2> filename" is used to forward errors to a file in Linux. The number "2" represents the standard error stream, and the "> filename" redirects the output to the specified file. This allows any error messages generated by a command to be saved in a file for later analysis or troubleshooting.

    Rate this question:

  • 10. 

    How can you display a list of all files, including the hidden files?

    • A.

      Ls -a

    • B.

      Find -a

    • C.

      Find all

    • D.

      All

    Correct Answer
    A. Ls -a
    Explanation
    The correct answer is "ls -a". The "ls" command is used to list files and directories in a directory. The "-a" option is used to display all files, including hidden files, in the directory. Therefore, "ls -a" is the correct command to display a list of all files, including hidden files.

    Rate this question:

  • 11. 

    How will you list only the empty lines in a file (using grep)?

    • A.

      Grep “$^” filename.txt

    • B.

      Grep “$” filename.txt

    • C.

      Grep “^$” filename.txt

    • D.

      Grep $^ filename.txt

    Correct Answer
    C. Grep “^$” filename.txt
    Explanation
    The correct answer is "grep “^$” filename.txt". This command uses the grep utility with the regular expression "^$" to search for lines that contain nothing between the start and end of the line. This effectively matches empty lines in the file "filename.txt".

    Rate this question:

  • 12. 

    How do you read arguments in a shell program?

    • A.

      $0 would be the first line argument, $1 would be the Second command line argument, $2 the Third, and so on

    • B.

      $1 would be the first command line argument, $2 the second, and so on $0 is the name of the script or function

    • C.

      Both a and b are correct

    • D.

      Both a and b are incorrect

    Correct Answer
    B. $1 would be the first command line argument, $2 the second, and so on $0 is the name of the script or function
    Explanation
    The correct answer is that $1 would be the first command line argument, $2 would be the second, and so on. This is because in a shell program, arguments passed from the command line are assigned to variables starting from $1, $2, $3, and so on. $0, on the other hand, represents the name of the script or function itself. Therefore, both options a and b are incorrect.

    Rate this question:

  • 13. 

    Which of the following is NOT a proper shell name?

    • A.

      Csh : C shell

    • B.

      Ksh : Korn Shell

    • C.

      Bash : bourne again shell

    • D.

      Ssh : sea shell

    Correct Answer
    D. Ssh : sea shell
    Explanation
    The given options are all shell names except for "ssh: sea shell". This is not a proper shell name as "ssh" stands for Secure Shell, which is a network protocol for secure remote login and other secure network services. It is not a type of shell used for command line interfaces.

    Rate this question:

  • 14. 

    In Shell scripting, what does '$?' return?

    • A.

      $? will return exit status of command .0 if command gets successfully executed ,non-zero if command failed.

    • B.

      $? will return exit status of command .Non-0 if command gets successfully executed ,zero if command failed.

    • C.

      System error

    • D.

      Invalid command

    Correct Answer
    A. $? will return exit status of command .0 if command gets successfully executed ,non-zero if command failed.
    Explanation
    The correct answer is that $? will return the exit status of a command. If the command is executed successfully, the exit status will be 0. If the command fails, the exit status will be a non-zero value.

    Rate this question:

  • 15. 

    In Shell scripting What does $# stand for?

    • A.

      Will return no of error

    • B.

      # will return the number of parameters that are passed as the command-line arguments.

    • C.

      Error

    • D.

      All the above are incorrect

    Correct Answer
    B. # will return the number of parameters that are passed as the command-line arguments.
    Explanation
    In Shell scripting, the symbol $# represents the number of parameters that are passed as command-line arguments. This means that it will return the count of arguments that are provided when executing the shell script. It does not represent the number of errors or any other options mentioned in the question.

    Rate this question:

  • 16. 

    In Shell scripting, what is  $*?

    • A.

      It's mainly used for showing all params. This shows a few parameter values passed in the shell script.

    • B.

      It's mainly used for showing all params. This shows all values returned.

    • C.

      It's mainly used for showing all params. This shows all parameter values passed in the shell script.

    • D.

      None of the above is correct.

    Correct Answer
    C. It's mainly used for showing all params. This shows all parameter values passed in the shell script.
    Explanation
    $* is a special variable in shell scripting that is used to display all the parameter values passed in a shell script. It allows the script to access and manipulate all the arguments provided when the script is executed. This is useful when a script needs to work with multiple inputs or parameters.

    Rate this question:

  • 17. 

    How can you get/set an environment variable from a program?

    • A.

      Getenv() and putenv()

    • B.

      Getenv() and setenv()

    • C.

      Readenv() and putenv()

    • D.

      Readenv() and setenv()

    Correct Answer
    A. Getenv() and putenv()
    Explanation
    The correct answer is getenv() and putenv(). The getenv() function is used to retrieve the value of an environment variable, while the putenv() function is used to set or change the value of an environment variable. These functions are commonly used in programming to interact with the environment variables of a system.

    Rate this question:

  • 18. 

    To change mode of myfile to 'rwxr–r–'  , the command used is

    • A.

      Chmod(myfile,0742).

    • B.

      Chmod(myfile,0474).

    • C.

      Chmod(myfile,0747).

    • D.

      Chmod(myfile,0744)

    Correct Answer
    D. Chmod(myfile,0744)
    Explanation
    The correct answer is "chmod(myfile,0744)". The "chmod" command is used to change the permissions of a file or directory. In this case, the "myfile" is being changed to "rwxr--r--", which means the owner has read, write, and execute permissions, while the group and others have only read permission. The numbers in the command represent the permissions in octal form, with the first digit representing the owner's permissions, the second digit representing the group's permissions, and the third digit representing others' permissions.

    Rate this question:

  • 19. 

    All UNIX files have their description stored in a structure called 'inode.' Which of the below fields are not part of the inode?

    • A.

      File access count

    • B.

      File owner identifier

    • C.

      File type

    • D.

      File access permissions

    Correct Answer
    A. File access count
    Explanation
    The file access count is not part of the inode structure in UNIX. The inode contains information about the file owner identifier, file type, and file access permissions. The file access count refers to the number of times the file has been accessed and is typically stored separately from the inode.

    Rate this question:

  • 20. 

    Which of the below commands is NOT used to view the contents of a file?

    • A.

      Ls command

    • B.

      Cat command

    • C.

      More command

    • D.

      Disp command

    Correct Answer
    D. Disp command
    Explanation
    The disp command is not used to view the contents of a file. The ls command is used to list the files in a directory, the cat command is used to display the contents of a file, and the more command is used to view the contents of a file one screen at a time. However, the disp command is not a valid command for viewing file contents.

    Rate this question:

  • 21. 

    How do you find out what’s your shell?

    • A.

      Whomami

    • B.

      Pwd

    • C.

      Echo $SHELL

    • D.

      $sh

    Correct Answer
    C. Echo $SHELL
    Explanation
    The correct answer is "echo $SHELL". This command is used to display the current shell being used by the user. The "$SHELL" is a system variable that holds the path to the current shell executable. By using the "echo" command, the value of the "$SHELL" variable is printed to the console, revealing the user's current shell.

    Rate this question:

  • 22. 

    Fork() command is used to create a new process. State true or false. 

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The fork() command is indeed used to create a new process. When the fork() command is executed, it creates a new process by duplicating the existing process. The new process, known as the child process, is an exact copy of the parent process, except for a few differences in process ID and memory address. Therefore, the correct answer is true.

    Rate this question:

Samy Boulos |MSc (Computer Science) |
Data Engineer
Samy Boulos is an experienced Technology Consultant with a diverse 25-year career encompassing software development, data migration, integration, technical support, and cloud computing. He leverages his technical expertise and strategic mindset to solve complex IT challenges, delivering efficient and innovative solutions to clients.

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Sep 16, 2024
    Quiz Edited by
    ProProfs Editorial Team

    Expert Reviewed by
    Samy Boulos
  • Dec 13, 2010
    Quiz Created by
    21Centurians
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.