logo
  • Home
  • Test & Rank
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Mining
  • Marine
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Jobs
  • Contact

Linux Multiple Choice Questions | MCQs | Quiz

Linux Interview Questions and Answers
Practice Linux questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Linux Environment - 1
•   Linux Environment - 2
•   Linux Environment - 3
•   Linux Commands - 1
•   Linux Commands - 2
•   Linux Commands - 3
•   Linux Commands - 4
•   Linux File Management - 1
•   Linux File Management - 2
•   Linux File Types
•   Linux File Permissions - 1
•   Linux File Permissions - 2
•   Linux File System Overview
•   Linux Startup & Shutdown
•   Linux Process Management
•   User Account Management
•   Linux Shell Programming
•   Linux Shell Environment - 1
•   Linux Shell Environment - 2
•   Linux Shell Redirection
•   Shell Special Symbols
•   Linux Search Pattern
•   Linux Shell Functions
•   Linux Shell Variables
•   Bash Arithmetic Expression
•   Command History
•   Bash Built-in Commands
•   Bash Built-in Commands - 2
•   Bash Built-in Commands - 3
•   Linux vi Editor
•   Linux sed Editor
•   Awk Programming Basics
•   Programming Expressions
•   Awk Control Statements
•   Awk Variables & Arrays
•   Filesystem Hierarchy - 1
•   Filesystem Hierarchy - 2
•   Linux Proc Filesystem - 1
•   Linux Proc Filesystem - 2
•   Linux Proc Filesystem - 3
•   Linux Proc Filesystem - 4
•   Linux Proc Filesystem - 5
•   Makefile Questions - 1
•   Makefile Questions - 2
•   GCC Compiler Options - 1
•   GCC Compiler Options - 2
•   GCC Compiler Options - 3
•   GCC Compilation Stages-1
•   GCC Compilation Stages-2
•   Static Libraries Questions
•   Shared Libraries Questions
•   GDB Debugger Questions-1
•   GDB Debugger Questions-2
•   GDB Debugger Questions-3
•   GDB Debugger Questions-4
•   GDB Debugger Questions-5
•   Linux Sysfs Questions - 1
•   Linux Sysfs Questions - 2
•   Linux Sysfs Questions - 3
•   Linux Sysfs Questions - 4
•   Linux Sysfs Questions - 5
•   Linux Device Drivers
•   Linux Process Management
•   Linux Memory Management
•   Linux File Management - 1
•   Linux File Management - 2
•   Linux Signal Handling
•   Linux IPCs - 1
•   Linux IPCs - 2
•   Linux Systems
•   ↓ Debugging Questions ↓
•   Debugging Malloc/Free-1
•   Debugging Malloc/Free-2
•   Debugging File Handling
•   Process Management
•   Debugging Signal Handling
•   Debugging Userlimit/Timer
•   Debugging Posix Threads
•   PThreads Handling
•   Debugging Pipes
•   Debugging System-V IPCs
•   Debugging POSIX IPCs
•   Debugging Unix Sockets
•   Debugging Internet Sockets

Best Reference Books

•   Linux Books
« Prev Page
Next Page »

Linux Shell Programming Questions and Answers – Variables

Posted on February 15, 2013 by Manish
This set of Linux / Unix questions and answers focuses on variables in Linux Shell Programming.

1. In the shell, by default, all variables are considered and stored as
a) string
b) integer
c) character
d) float
View Answer

Answer: a
Explanation: None.

2. Which command reads user input from the terminal and assign this value to a variable name?
a) read
b) get
c) declare
d) set
View Answer

Answer: a
Explanation: None.
advertisement

3. Which one of the following statement is true about variables in shell?
a) variables do not require declaration before assigning value to them
b) variables are case sensitive
c) to extract the contents of a variable, we have to provide the variable a preceding $
d) all of the mentioned
View Answer

Answer: d
Explanation: None.

4. Which one of the following is not a valid shell variable?
a) _san
b) san_2
c) _san_2
d) 2_san
View Answer

Answer: d
Explanation: The shell variable can contain only letters(a to z or A to Z), numbers(0 to 9), or a underscore character(_) and a variable can not start with a number.

5. To redefine a variable, it can be removed from the list of variables by using the command
a) unset
b) delete
c) remove
d) clear
View Answer

Answer: a
Explanation: None.

6. What is the output of this program?

  1.    #!/bin/bash
  2.    san_var="Sanfoundry"
  3.    echo "$san_var"
  4.    echo '$san_var'
  5.    echo '"$san_var"'
  6.    echo "'$san_var'"
  7.    echo \$san_var
  8.    exit 0

a) Sanfoundry
$san_var
“$san_var”
‘Sanfoundry’
$san_var
b) Sanfoundry
Sanfoundry
“Sanfoundry”
‘Sanfoundry’
Sanfoundry
c) program will generate an error message
d) program will print nothing
View Answer

Answer: a
Explanation: Using double quotes does not affect the substitution of the variable, while single quotes and backslash do.
Output:
[email protected]:/home/sanfoundry# ./test.sh
Sanfoundry
$san_var
“$san_var”
‘Sanfoundry’
$san_var
[email protected]:/home/sanfoundry#
advertisement

7. What is the output of this program?

  1.    #!/bin/bash
  2.    var1=10
  3.    $var1=20
  4.    echo $var1
  5.    exit 0

a) program will print 10
b) program will generate a warning message
c) program will print 20
d) program will print 10 & 20
View Answer

Answer: d
Explanation: The doller sign ($) is used to access a variable’s value, not to define it.
Output:
[email protected]:/home/sanfoundry# ./test.sh
./test.sh: line 3: 10=20: command not found
10
[email protected]:/home/sanfoundry#

8. What is the output of this program?

  1.    #!/bin/bash
  2.    var[1]=san_1
  3.    var[2]=san_2
  4.    var[3]=san_3
  5.    echo ${var[*]}
  6.    exit 0

a) san_1
b) san_2
c) san_3
d) san_1 san_2 san_3
View Answer

Answer: d
Explanation: All items of an array can be accessed by using ${[*]} or ${[@]}.
Output:
[email protected]:/home/sanfoundry# ./test.sh
san_1 san_2 san_3
[email protected]:/home/sanfoundry#
advertisement

9. What is the output of this program?

  1.    #!/bin/bash
  2.    san_var=hello
  3.    readonly san_var
  4.    san_var=hi
  5.    echo $san_var
  6.    exit 0

a) hello
b) hi
c) nothing will print
d) none of the mentioned
View Answer

Answer: a
Explanation: After the execution of the ‘readonly’ command, shell will not provide the permission to overwrite the value stored in variable ‘san_var’.
Output:
[email protected]:/home/sanfoundry# ./test.sh
./test.sh: line 4: san_var: readonly variable
hello
[email protected]:/home/sanfoundry#

10. What is the output of this program?

  1.     #!/bin/bash
  2.     san_var=10
  3.     echo "the value of \"san_var\" is $san_var"  
  4.     exit 0

a) the value of “san_var” is 10
b) the value of is 10
c) the value of san_var is $san_var
d) the value of “san_var” is $san_var
View Answer

Answer: a
Explanation: None.
Output:
[email protected]:/home/sanfoundry# ./test.sh
the value of “san_var” is 10
[email protected]:/home/sanfoundry#

Sanfoundry Global Education & Learning Series – Linux Administration & Programming.

Here’s the list of Best Reference Books in Linux Commands & Shell Programming.
Here’s the list of Best Reference Books in Linux Kernel, Device-Drivers & System Programming.

To practice all questions on Linux Administration & Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on Linux.

« Prev Page - Linux Shell Programming Questions and Answers – Functions
» Next Page - Linux Bash Shell Questions & Answers – Arithmetic Expressions

« Linux Shell Programming Questions and Answers – Functions
C Program to Display Upper Triangular Matrix »
advertisement

Deep Dive @ Sanfoundry:

  1. Java Programming Examples on Numerical Problems & Algorithms
  2. C Programming Examples on File Handling
  3. C++ Programming Examples on STL
  4. C Programming Examples on Bitwise Operations
  5. Online Training – SAN, C, Linux Kernel & Device Drivers Training
  6. C Programming Examples on Data-Structures
  7. C Programming Examples on Puzzles & Games
  8. Bangalore Training – SAN, C, Linux Kernel and Device Drivers Training
  9. Linux Command Tutorials with Examples and Explanations
  10. Linux Questions and Answers
Manish Bhojasia
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Facebook | Twitter

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.