DevOps

Shell Scripting & Bash

Variables, loops, conditionals, functions, pipes, redirections

20 면접 질문·
Mid-Level
1

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

답변

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?

답변

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?

답변

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 면접 질문

다음 면접을 위해 DevOps을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기