Discussion
What happens when the command echo $0 is executed inside a shell script ?
Answer: B
The keyed answer is that it prints the name of the shell executing the script.
$0 is the shell's special parameter for the name of the program that is running. In an interactive shell, echo $0 prints the shell's own name, such as bash. Strictly, inside a script it holds the name by which the script was invoked, for example ./backup.sh; the options do not offer that, and the paper's option B is its description of $0 as the name of the running program.
The other options belong to other parameters and commands. The last exit status is $?. The current working directory is printed by pwd. The first argument to a script is $1, a common mix-up with $0.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development