Shell Scripting

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 Uwinpro
U
Uwinpro
Community Contributor
Quizzes Created: 25 | Total Attempts: 13,623
Questions: 30 | Attempts: 1,163

SettingsSettingsSettings
Shell Scripting - Quiz

Test your Shell scripting skills.
Good Luck !


Questions and Answers
  • 1. 

    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 answer "ssh : sea shell" is not a proper shell name because "sea shell" is not a recognized shell in the Unix/Linux operating system. The other options, csh, ksh, and bash, are all legitimate shell names commonly used in Unix/Linux systems.

    Rate this question:

  • 2. 

    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. It will return 0 if the command gets successfully executed and a non-zero value if the command fails.

    Rate this question:

  • 3. 

    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.

      None of the above

    Correct Answer
    B. Will return the number of parameters that are passed as the command-line arguments
    Explanation
    The correct answer is "Will return the number of parameters that are passed as the command-line arguments." In Shell scripting, the special variable "$#" represents the number of parameters that are passed as command-line arguments. It is often used to determine the number of arguments provided to a script or function.

    Rate this question:

  • 4. 

    In Shell scripting, what is  $*?

    • A.

      Its mainly used for showing up all params. This show few parameter values passed in shell script

    • B.

      Its mainly used for showing up all params. This show all values returned

    • C.

      Its mainly used for showing up all params. This show all parameter values passed in shell script

    • D.

      None of the above

    Correct Answer
    C. Its mainly used for showing up all params. This show all parameter values passed in 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 is mainly used to show all the parameter values passed in the script.

    Rate this question:

  • 5. 

    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" because the command "echo" is used to display the value of the environment variable "$SHELL", which stores the path to the current user's shell. By executing this command, the shell will return the path to the current shell being used.

    Rate this question:

  • 6. 

    Why should the Bourne shell be used for writing shell scripts?

    • A.

      Easily available

    • B.

      Standard and portable

    • C.

      Easy to use

    • D.

      Available on all the system

    Correct Answer
    B. Standard and portable
    Explanation
    The Bourne shell should be used for writing shell scripts because it is standard and portable. This means that scripts written in the Bourne shell can be easily run on different systems without any compatibility issues. It provides a consistent and reliable scripting environment, making it a preferred choice for writing shell scripts. Additionally, being widely available and easy to use further adds to its advantages.

    Rate this question:

  • 7. 

    How do shell scripts receive input?

    • A.

      By reading keyboard data entered by a user

    • B.

      By using the output of another program as input

    • C.

      By using a file’s contents as input

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    Shell scripts can receive input in multiple ways. They can read keyboard data entered by a user, use the output of another program as input, or use a file's contents as input. Therefore, the correct answer is "All of the above."

    Rate this question:

  • 8. 

    Which one of the following files contains the name of your login shell?

    • A.

      /etc/passwd

    • B.

      /etc/login

    • C.

      /etc/hosts

    • D.

      /etc/profile

    Correct Answer
    A. /etc/passwd
    Explanation
    The correct answer is /etc/passwd. The /etc/passwd file is a system file that contains information about user accounts on a Unix-like operating system. It stores the username, user ID, group ID, home directory, and login shell of each user. Therefore, the name of the login shell can be found in this file.

    Rate this question:

  • 9. 

    When a shell script begins, it has an initial value for the PATH variable. Where does this value come from?

    • A.

      It’s passed down from the script’s parent shell

    • B.

      It’s passed up from the script’s child shell

    • C.

      It’s read by the script from the /etc/profile file

    • D.

      It’s read by the script from the .profile file.

    Correct Answer
    A. It’s passed down from the script’s parent shell
    Explanation
    The initial value for the PATH variable in a shell script is passed down from the script's parent shell. This means that when the script is executed, it inherits the value of the PATH variable from the shell that launched it.

    Rate this question:

  • 10. 

    Which shell is the parent process of the Korn shell seen in the listing above?

    • A.

      The Korn Shell

    • B.

      The Bourne shell

    • C.

      The C shell

    • D.

      The bash shell

    Correct Answer
    C. The C shell
    Explanation
    The C shell is the parent process of the Korn shell seen in the listing above.

    Rate this question:

  • 11. 

    Which quoting mechanism is used to protect $, > and * from shell?  

    • A.

      Single

    • B.

      Double

    • C.

      Back quote

    • D.

      None of the above

    Correct Answer
    A. Single
    Explanation
    The single quoting mechanism is used to protect special characters like $, >, and * from being interpreted by the shell. When a string is enclosed in single quotes, the shell treats it as a literal string and does not expand variables or interpret special characters within it. This ensures that the characters are treated as regular characters and not as part of any shell command or operation.

    Rate this question:

  • 12. 

    Study the following steps: name=cat namelast=meow echo $name `echo last` How can the above echo command be modified to display the string meow?

    • A.

      Eval echo \$name `echo last`

    • B.

      Eval ‘$name’ `echo last`

    • C.

      Echo “$name” $namelast

    • D.

      Both eval echo \$name `echo last` & eval ‘$name’ `echo last`

    Correct Answer
    D. Both eval echo \$name `echo last` & eval ‘$name’ `echo last`
    Explanation
    Both options "eval echo \$name `echo last`" and "eval ‘$name’ `echo last`" will display the string "meow" because they use the "eval" command to evaluate the value of the variable "name" and then concatenate it with the result of the command "echo last". This will result in the string "meow" being displayed. The other options do not include the necessary evaluation of the variable and will not display the desired string.

    Rate this question:

  • 13. 

    How to check if a file is present in a particular directory in Unix?

    • A.

      Ls –l myFile.txt; echo $?

    • B.

      Ls –l myFile.txt; echo $#

    • C.

      Ls –l myFile.txt; echo $$

    • D.

      Ls –l myFile.txt; echo $*

    Correct Answer
    A. Ls –l myFile.txt; echo $?
    Explanation
    The correct answer is "ls –l myFile.txt; echo $?" because the "$?" variable in Unix stores the exit status of the previous command. In this case, the "ls -l myFile.txt" command is used to list the file details, and the "echo $?" command is used to display the exit status. If the file is present in the directory, the exit status will be 0, indicating success. If the file is not present, the exit status will be 1, indicating failure.

    Rate this question:

  • 14. 

    How to remove the last line/ trailer from a file in UNIX?

    • A.

      Sed –i '^ d' file.txt

    • B.

      Sed –i '$ d' file.txt

    • C.

      Sed –i '$ p' file.txt

    • D.

      Sed –i '$ c' file.txt

    Correct Answer
    B. Sed –i '$ d' file.txt
    Explanation
    The correct answer is "sed –i '$ d' file.txt". In sed command, the option -i is used to edit the file in-place. The '$' represents the last line of the file and 'd' is the command used to delete the line. Therefore, the command "sed –i '$ d' file.txt" will remove the last line or trailer from the file in UNIX.

    Rate this question:

  • 15. 

    Which command is used to sort the lines of data in a file in reverse order?

    • A.

      Sort

    • B.

      Sh

    • C.

      St

    • D.

      Sort -r

    Correct Answer
    D. Sort -r
    Explanation
    The command "sort -r" is used to sort the lines of data in a file in reverse order. The "-r" flag stands for reverse, indicating that the sorting should be done in descending order instead of ascending order. This command is useful when you want to arrange the lines of data in a file in reverse alphabetical or numerical order.

    Rate this question:

  • 16. 

    Which command is used to display the top of the file?

    • A.

      Cat

    • B.

      Head

    • C.

      More

    • D.

      Grep

    Correct Answer
    B. Head
    Explanation
    The "head" command is used to display the top of a file. It allows users to view the first few lines of a file, typically the first 10 lines by default. This command is commonly used to quickly check the contents of a file without having to open the entire file.

    Rate this question:

  • 17. 

    Which symbol will be used with grep command to match the pattern pat at the beginning of a line?

    • A.

      ^pat

    • B.

      $pat

    • C.

      Pat$

    • D.

      Pat^

    Correct Answer
    A. ^pat
    Explanation
    The symbol "^" is used with the grep command to match the pattern "pat" at the beginning of a line. This symbol signifies the start of a line, so using it before the pattern ensures that the pattern is only matched if it appears at the beginning of a line.

    Rate this question:

  • 18. 

    Which command is used to change protection mode of files starting with the string emp and ending with 1,2, or 3?

    • A.

      Chmod u+x emp[l-3]

    • B.

      Chmod 777 emp*

    • C.

      Chmod u+r ??? emp

    • D.

      Chmod 222 emp?

    Correct Answer
    A. Chmod u+x emp[l-3]
    Explanation
    The correct answer is "chmod u+x emp[l-3]". This command uses the "chmod" command to change the protection mode of files starting with the string "emp" and ending with the numbers 1, 2, or 3. The "[l-3]" part specifies a range of numbers from l to 3, so it will match any of the specified endings. The "u+x" part of the command adds execution permission for the owner of the files.

    Rate this question:

  • 19. 

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

    • A.

      All

    • B.

      Ls -a

    • C.

      Find -a

    • D.

      Find all

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

    Rate this question:

  • 20. 

    How to create a new file without opening it?

    • A.

      Less filename

    • B.

      Touch filename

    • C.

      More filename

    • D.

      Cat filename

    Correct Answer
    B. Touch filename
    Explanation
    The correct answer is "touch filename". The touch command is used to create a new file without opening it. It updates the access and modification timestamps of the file, and if the file does not exist, it creates a new empty file with the specified name. This command is commonly used in Unix-like operating systems to create new files quickly and efficiently.

    Rate this question:

  • 21. 

    What do you use to forward errors to a file?

    • A.

      2> filename

    • B.

      2> /dev/null

    • C.

      &> filename

    • D.

      Filename

    Correct Answer
    A. 2> filename
    Explanation
    The correct answer is "2> filename". In Unix-like operating systems, the "2>" syntax is used to redirect the standard error stream to a file. By using this syntax followed by the desired filename, any error messages or output generated by a command will be written to the specified file instead of being displayed on the screen. This is useful for capturing and analyzing error information for troubleshooting purposes.

    Rate this question:

  • 22. 

    With what can you stop a process? 

    • A.

      Delete

    • B.

      Kill

    • C.

      Stop

    • D.

      Shutdown

    Correct Answer
    B. Kill
    Explanation
    You can stop a process by using the "Kill" command. This command terminates a running process forcefully, effectively stopping it. It is commonly used in operating systems to end a program or process that is not responding or causing issues. By using the "Kill" command, you can forcefully stop a process and free up system resources.

    Rate this question:

  • 23. 

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

    • A.

      Place

    • B.

      Map

    • C.

      Whereami

    • D.

      Pwd

    Correct Answer
    D. Pwd
    Explanation
    The "pwd" command stands for "print working directory." When this command is executed in a command line interface, it displays the full path of the current working directory. This allows the user to easily determine which folder they are currently in. Therefore, the correct answer to the question is "pwd."

    Rate this question:

  • 24. 

    Which command is most useful when you want not only to send some data down a pipe, but also to save a copy?

    • A.

      Pipe

    • B.

      Awk

    • C.

      Split

    • D.

      Tee

    Correct Answer
    D. Tee
    Explanation
    The command "tee" is the most useful when you want to send data down a pipe and also save a copy. Tee reads from standard input and writes to standard output and files simultaneously. It allows you to redirect the output of a command to both a file and another command or multiple files. This is helpful when you want to save a copy of the data for future reference or analysis while still passing it along for further processing.

    Rate this question:

  • 25. 

    Shell programs are?

    • A.

      Compiled

    • B.

      Interpreted

    • C.

      Command processed

    • D.

      None of the above

    Correct Answer
    B. Interpreted
    Explanation
    Shell programs are interpreted. This means that they are executed line by line by an interpreter, rather than being compiled into machine code beforehand. The interpreter reads each line of the program and immediately executes the corresponding command or instruction. This allows for quick and easy development and testing of shell scripts, as changes can be made and executed immediately without the need for a compilation step.

    Rate this question:

  • 26. 

    The name of the Unix scheduling utility is?

    • A.

      Sched

    • B.

      Cron

    • C.

      Sc

    • D.

      Timer

    Correct Answer
    B. Cron
    Explanation
    The correct answer is "Cron". Cron is a Unix scheduling utility that allows users to schedule commands or scripts to run automatically at specified times or intervals. It is commonly used for tasks such as system maintenance, backups, and batch processing. Cron is a powerful tool that helps automate repetitive tasks and improve system efficiency.

    Rate this question:

  • 27. 

    Applications of Shell programming include?

    • A.

      Simplifying complex jobs

    • B.

      Automating repetitive tasks

    • C.

      Both of the Above

    • D.

      None of the Above

    Correct Answer
    C. Both of the Above
    Explanation
    Shell programming is a powerful tool that can simplify complex jobs and automate repetitive tasks. By writing scripts in a shell language, users can create a series of commands that can be executed together, saving time and effort. This can be particularly useful for tasks that need to be performed regularly or involve multiple steps. Therefore, the correct answer is "Both of the Above" as shell programming can be used to simplify complex jobs and automate repetitive tasks.

    Rate this question:

  • 28. 

    Flow control in a shell program allows parts of a shell program to be executed _______

    • A.

      Repeatedly

    • B.

      Conditionally

    • C.

      Both of the Above

    • D.

      None of the Above

    Correct Answer
    C. Both of the Above
    Explanation
    Flow control in a shell program allows parts of a shell program to be executed repeatedly or conditionally. This means that certain sections of the program can be executed multiple times in a loop, or they can be executed based on a specific condition being met. Both options provide flexibility and control over the execution of the program, allowing for efficient and dynamic programming.

    Rate this question:

  • 29. 

    Which of the following is not true of program variables?

    • A.

      Can be exported to the entire system

    • B.

      Can be used only within the shell program

    • C.

      Can hold data

    • D.

      All of the above

    Correct Answer
    A. Can be exported to the entire system
    Explanation
    Program variables cannot be exported to the entire system. They are limited to the scope of the program or script in which they are defined. They can be used within the shell program or script and can hold data, but they are not accessible or visible outside of the program or script unless specifically exported or shared.

    Rate this question:

  • 30. 

    Look at the following ps –f command : UID   PID  PPID  C    STIME TTY      TIME CMD

    • A.

      Student 3763 3762 0 00:20:09 pts/1 0:00 /bin/sh

    • B.

      Student 3762 3750 0 00:20:03 pts/1 0:00 /bin/ksh

    • C.

      Student 3750 3748 0 00:19:23 pts/1 0:00 /bin/csh

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    The given output of the ps -f command shows the process information in a tabular format. Each row represents a process, and the columns display the UID (user ID), PID (process ID), PPID (parent process ID), C (CPU usage), STIME (start time), TTY (terminal), TIME (CPU time), and CMD (command). The output shows three processes with different PIDs, PPIDs, and commands (/bin/sh, /bin/ksh, and /bin/csh). Therefore, the correct answer is "All of the above" because it includes all the processes listed in the output.

    Rate this question:

Quiz Review Timeline +

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

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 29, 2012
    Quiz Created by
    Uwinpro
Advertisement