100% de satisfacción garantizada Inmediatamente disponible después del pago Leer en línea o como PDF No estas atado a nada 4,6 TrustPilot
logo-home
Examen

Shell Scripting using Bash (SC103) Practice Exam

Puntuación
-
Vendido
-
Páginas
134
Grado
A+
Subido en
16-12-2024
Escrito en
2024/2025

The Shell Scripting using Bash (SC103) Practice Exam is designed for IT professionals specializing in shell scripting using the Bash shell. Topics include scripting fundamentals, automation, process management, and system administration tasks. Candidates are tested on their ability to write, debug, and optimize Bash scripts to automate tasks, manage system resources, and enhance operational efficiency in Unix/Linux environments.

Mostrar más Leer menos
Institución
Computer Tech
Grado
Computer Tech

Vista previa del contenido

Shell Scripting using Bash (SC103) Exam


1. What is the purpose of the read command in Bash?

a) To write data to a file
b) To read input from the user
c) To execute a script
d) To define a variable
Answer: b) To read input from the user
Explanation: The read command is used to accept user input from the standard input
(keyboard) and assign it to a variable.

2. How can you prompt the user for input in a Bash script?

a) echo "Enter your name:"
b) read -p "Enter your name: " name
c) prompt "Enter your name:"
d) input "Enter your name:"
Answer: b) read -p "Enter your name: " name
Explanation: The -p option allows you to provide a prompt directly with the read
command.

3. Which of the following commands will store the current directory in a
variable named current_dir?

a) current_dir=$(pwd)
b) current_dir=pwd
c) current_dir=cd
d) current_dir="pwd"
Answer: a) current_dir=$(pwd)
Explanation: The $(pwd) command substitution gets the current working directory and
assigns it to the current_dir variable.

4. How do you access the first argument passed to a Bash script?

a) $1
b) $2
c) $0
d) $*
Answer: a) $1
Explanation: In Bash scripts, $1 refers to the first argument passed to the script.

5. Which command will exit a Bash script with a status of 1?

a) exit 0
b) return 1


1

, Shell Scripting using Bash (SC103) Exam


c) exit 1
d) quit 1
Answer: c) exit 1
Explanation: The exit command is used to terminate a script and return an exit status. exit
1 indicates an error or abnormal termination.

6. How can you use a variable inside a double-quoted string in Bash?

a) ${variable}
b) $(variable)
c) ^variable
d) variable[]
Answer: a) ${variable}
Explanation: Inside double quotes, variables can be used with ${variable} to ensure
correct interpretation and expansion.

7. Which of the following will list files in the current directory?

a) ls
b) dir
c) list
d) files
Answer: a) ls
Explanation: The ls command lists the files and directories in the current directory.

8. How do you make a Bash script executable?

a) chmod 755 script.sh
b) chmod +x script.sh
c) chmod 777 script.sh
d) chmod 644 script.sh

Answer: b) chmod +x script.sh
Explanation: The chmod +x command adds execute permissions to the script file.

9. What does the #!/bin/bash line at the beginning of a script do?

a) Specifies the interpreter for the script
b) Comments out the line
c) Defines a variable
d) Sets the script's execution time
Answer: a) Specifies the interpreter for the script
Explanation: The #!/bin/bash line, called a shebang, indicates that the script should be run
using the Bash interpreter.



2

, Shell Scripting using Bash (SC103) Exam


10. How can you handle errors in a Bash script?

a) By using if statements
b) By using try-catch blocks
c) By checking exit statuses
d) By ignoring errors
Answer: c) By checking exit statuses
Explanation: You can handle errors by checking the exit statuses of commands using $? to
determine if the last command was successful or not.

11. What does the && operator do in a Bash command?

a) Executes the second command only if the first command fails
b) Executes the second command only if the first command succeeds
c) Runs commands in parallel
d) Runs commands sequentially regardless of success
Answer: b) Executes the second command only if the first command succeeds
Explanation: The && operator allows you to execute the second command only if the first
command returns a success status (exit status 0).

12. How can you make a script pause for 5 seconds?

a) sleep 5
b) wait 5
c) pause 5
d) delay 5
Answer: a) sleep 5
Explanation: The sleep command pauses the execution of a script for a specified number of
seconds.

13. What does the > operator do in Bash?

a) Redirects output to a file, overwriting the file if it exists
b) Appends output to a file
c) Redirects input from a file
d) Executes a command in the background
Answer: a) Redirects output to a file, overwriting the file if it exists
Explanation: The > operator redirects the output of a command to a file, replacing the file's
contents if it already exists.

14. How can you append output to an existing file in Bash?

a) command >> file
b) command > file



3

, Shell Scripting using Bash (SC103) Exam


c) command << file
d) command 2> file
Answer: a) command >> file
Explanation: The >> operator appends the output of a command to a file without overwriting
its existing contents.

15. What is the purpose of the echo command in Bash?

a) To execute a command
b) To display a line of text
c) To create a file
d) To delete a file
Answer: b) To display a line of text
Explanation: The echo command outputs text to the terminal or to a file.

16. How do you define a variable in Bash?

a) var=value
b) var: value
c) var = value
d) var-value
Answer: a) var=value
Explanation: Variables in Bash are defined by using the syntax var=value without spaces
around the = sign.

17. How can you list all environment variables in Bash?

a) listenv
b) env
c) showenv
d) printenv
Answer: d) printenv
Explanation: The printenv command lists all environment variables and their values.

18. What does the $(command) syntax do?

a) Runs the command in the background
b) Substitutes the output of the command
c) Creates a new command
d) Executes the command on a remote server
Answer: b) Substitutes the output of the command
Explanation: The $(command) syntax is used for command substitution, where the output of
the command replaces the $(command) expression.

19. How can you access all command-line arguments passed to a script?
4

Escuela, estudio y materia

Institución
Computer Tech
Grado
Computer Tech

Información del documento

Subido en
16 de diciembre de 2024
Número de páginas
134
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas

Temas

$85.99
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Leer en línea o como PDF
No estas atado a nada

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
nikhiljain22 EXAMS
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
950
Miembro desde
1 año
Número de seguidores
33
Documentos
23119
Última venta
1 hora hace

3.5

223 reseñas

5
74
4
49
3
46
2
16
1
38

Documentos populares

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes