Shell Scripting

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Uwinpro
U
Uwinpro
Community Contributor
Quizzes Created: 25 | Total Attempts: 14,011
| Attempts: 1,194 | Questions: 30
Please wait...
Question 1 / 30
0 %
0/100
Score 0/100
1. How can you display a list of all files, including the hidden files?

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.

Submit
Please wait...
About This Quiz
Language Quizzes & Trivia

This Shell Scripting quiz assesses knowledge on various shell commands and scripting techniques. Topics include shell environments, script parameters, and command execution status. It's ideal for learners aiming to enhance their scripting skills for better automation and system management.

Tell us your name to personalize your report, certificate & get on the leaderboard!
2. In Shell scripting, What does $# stand for? 

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.

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

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.

Submit
4. With what can you stop a process? 

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.

Submit
5. Which command is used to display the top of the file?

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.

Submit
6. With what command you can see what folder you are in?

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."

Submit
7. How to create a new file without opening it?

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.

Submit
8. Which of the following is not a proper shell name?

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.

Submit
9. How do shell scripts receive input?

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."

Submit
10. In Shell scripting, What does $? Return? 

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.

Submit
11. Applications of Shell programming include?

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.

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

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.

Submit
13. How do you find out what's your 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.

Submit
14. Which command is used to change protection mode of files starting with the string emp and ending with 1,2, or 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.

Submit
15. In Shell scripting, what is  $*?

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.

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

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.

Submit
17. The name of the Unix scheduling utility is?

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.

Submit
18. What do you use to forward errors to a file?

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.

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

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.

Submit
20. Shell programs are?

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.

Submit
21. Why should the Bourne shell be used for writing shell scripts?

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.

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

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.

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

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.

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

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.

Submit
25. 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?

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.

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

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.

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

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.

Submit
28. Which of the following is not true of program variables?

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.

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

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.

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

Explanation

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

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

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
Cancel
  • All
    All (30)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
How can you display a list of all files, including the hidden files?
In Shell scripting, What does $# stand for? 
Which command is used to sort the lines of data in a file in reverse...
With what can you stop a process? 
Which command is used to display the top of the file?
With what command you can see what folder you are in?
How to create a new file without opening it?
Which of the following is not a proper shell name?
How do shell scripts receive input?
In Shell scripting, What does $? Return? 
Applications of Shell programming include?
Look at the following ps –f command :...
How do you find out what's your shell? 
Which command is used to change protection mode of files starting with...
In Shell scripting, what is  $*?
Which symbol will be used with grep command to match the pattern pat...
The name of the Unix scheduling utility is?
What do you use to forward errors to a file?
Flow control in a shell program allows parts of a shell program to be...
Shell programs are?
Why should the Bourne shell be used for writing shell scripts?
How to check if a file is present in a particular directory in Unix?
How to remove the last line/ trailer from a file in UNIX?
Which command is most useful when you want not only to send some data...
Study the following steps:...
Which one of the following files contains the name of your login...
When a shell script begins, it has an initial value for the PATH...
Which of the following is not true of program variables?
Which quoting mechanism is used to protect $, > and * from shell?...
Which shell is the parent process of the Korn shell seen in the...
Alert!

Advertisement