DevOps

Shell Scripting & Bash

Variables, loops, conditionals, functions, pipes, redirections

20 câu hỏi phỏng vấn·
Mid-Level
1

What is the correct syntax to declare a variable in Bash?

Câu trả lời

In Bash, a variable is declared without the dollar sign and without spaces around the equals sign. The variable name must start with a letter or underscore. To use the variable's value, prefix its name with the dollar sign ($). Spaces around the equals sign cause a syntax error because Bash interprets them as separate command arguments.

2

How to access the value of a variable named USERNAME in Bash?

Câu trả lời

To access a variable's value, prefix its name with the dollar sign ($). The syntax $USERNAME retrieves the value stored in the variable. The syntax ${USERNAME} can also be used, which offers more flexibility, especially for concatenation or using modifiers. Without the dollar sign, Bash interprets USERNAME as a literal string and not as a variable reference.

3

Which command allows exporting a variable to make it accessible to child processes?

Câu trả lời

The export command makes an environment variable available to all child processes launched from the current shell. Without export, a variable is local to the current shell and is not passed to subprocesses. This distinction is crucial when writing scripts that invoke other scripts or programs. It is possible to combine declaration and export in one line with export VAR=value.

4

How to capture the exit code of the last executed command?

5

What is the correct syntax for an if condition in Bash?

+17 câu hỏi phỏng vấn

Nắm vững DevOps cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí