This set of Unix Question Paper focuses on “Shell Variables – 2”.
1. Which symbol is used for setting the PS1 prompt to show the current event number?
Explanation: Bash and Korn shell also supports history facility that treats a previous command as an event and associates it with a number. Thus we can recall and execute previous commands by their event numbers. Using the !, we can set the PS1 prompt to show the current event number. For example,
$ PS1=’ [!] ’ //bash requires \ before !  _ // number associated Every time a command is executed, the event number is incremented.
2. Which escape sequence is used with PS1 to show the hostname of our computer?
Explanation: Bash uses a number of escape sequences to make our prompt as much information as possible. For example, the \h string will show the hostname of our computer.
$ PS1=”\h ” Saturn> _ //Saturn is the machine’s name
3. Which of the following shells support the use of aliases?
d) Korn and bash
Explanation: Bash and Korn shell supports the use of aliases which lets us assign shorthand names to frequently used commands. For example,
$ alias a1=’ls -l’ // quoting necessary for multiple words $ a1 // a1 will now execute the ls -l command
4. We can display an alias definition by using an alias with the name.
Explanation: Aliases lets us assign shorthand names to frequently used commands. We can display an alias definition using an alias with the name. For example,
$ alias a1 a1=’ls -l’
5. Which command is used in bash and Korn shells to display the previously used commands?
Explanation: Bash and Korn support a versatile history feature that treats a previous command as an event and associates it with an event number. The history command displays the history list showing the event number of every previously executed command.
6. To display the last five used commands, which one of the following commands is used (in bash shell)?
a) history 5
b) history -5
d) history 5-
Explanation: While bash displays the complete history list using history command. Korn lists the 16 commands recently used. But we can easily find out the last five commands by using a numeric argument:
$ history 5 // in bash $ history -5 // in Korn
7. Which of the following symbols are used for accessing previous commands by event numbers?
d) ! and r
Explanation: The ! symbol (r in Korn) is used to repeat previous commands. For repeating the last command we have to use !! in bash and r in Korn. We can repeat other commands also, but with the event number as an argument. For example, following commands will repeat the command with event number 38,
$ !38 // in bash $ r 38 // in Korn
8. We can use relative addressing while executing previous commands.
Explanation: Suppose if we don’t know the event number and we want to execute the command prior to the previous one, we can use relative addressing by using a negative argument with ! or r. For example,
$ !-2 //in bash $ r -2 //in Korn
9. We can also execute previous commands by context.
Explanation: It may happen that we don’t remember the event numbers of the commands except for the immediately preceding two or three, but we remember that the command started with a specific letter or string. In such a case, we can execute previous commands by context by using ‘v’ along with ! or r. For example,
$ !v // repeat last command beginning with v (in bash) $ rv // repeats last command beginning with v (in Korn)
10. Which symbol is used as a shorthand for using the last argument to the previous command?
Explanation: Sometimes we run several commands on the same file and instead of specifying the filename, again and again, we can use $ as a shorthand. This expression signifies the last argument to the previous command. For example,
$ mkdir prog_one // create a directory $ cd $ // change directory to mkdir
Sanfoundry Global Education & Learning Series – Unix.
To practice all questions papers on Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.