← all posts

Linux And Bash Fundamentals For DevOps

February 12, 2024
Linux And Bash Fundamentals For DevOps

DevOps work often fails on small Linux misunderstandings: environment variables that do not propagate, permissions that behave differently on files and directories, or scripts that assume the wrong shell behavior.

The fundamentals are worth making explicit.

Local Variables vs Environment Variables

In Bash, a local shell variable is visible in the current shell. An environment variable is exported to child processes.

name=app
export name

Use export when a script, subprocess, or command needs to inherit the value. Do not export everything by default.

This is one of the first real process-boundary lessons in Linux: shell state and process environment are related, but not the same thing.

source vs export

source ~/.bashrc runs a file in the current shell. This is why aliases and functions become available immediately.

export PATH="$HOME/bin:$PATH" changes the environment so child processes can find executables.

They solve different problems and are often used together.

People confuse them because they often appear in the same setup flow. One loads commands into the current shell. The other shapes what future child processes inherit.

File Permissions

Permissions mean different things for files and directories:

  1. File read: read contents.
  2. File write: modify contents.
  3. File execute: run as a program.
  4. Directory read: list names.
  5. Directory write: create or remove entries.
  6. Directory execute: enter or traverse the directory.

Many permission bugs are directory execute-bit bugs. Teams understand file permissions earlier than directory traversal semantics, so the bug feels mysterious until you know what x means on a directory.

Processes: fork And exec

fork() creates a child process. exec() replaces the current process image with a new program.

Most command execution is effectively fork then exec: the shell creates a child, then the child becomes the command.

Child processes inherit environment variables and file descriptors. They do not modify the parent shell's variables unless the parent explicitly reads their output.

This is the reason shell scripting feels counterintuitive at first. A command can print data back to the parent workflow, but it cannot silently reach backward and mutate the parent shell's memory.

Built-ins vs External Commands

Built-ins such as cd, export, and unset run inside the shell process. External commands such as grep, awk, sed, and curl run as separate executables.

This is why cd must be a built-in: an external process changing its own directory would not change the parent shell.

Built-ins are not just performance trivia. They exist because some operations only make sense inside the shell process itself.

Package Families

RHEL-family systems use RPM packages with yum or dnf. Debian-family systems use DEB packages with apt and dpkg.

Know the family before debugging package commands. Amazon Linux 2023 is Fedora-based, while Ubuntu is Debian-based.

That matters operationally because package assumptions leak into automation fast. A script that casually mixes apt, yum, and package names across families usually fails in the least helpful way.

Amazon Linux 2023 is also more deterministic than older Amazon Linux habits might lead you to expect. Its repository behavior is intentionally more controlled, which is useful for predictable fleet operations.

Practical Mindset

Linux automation is easier when you understand what crosses a process boundary, what stays in the current shell, and what permissions mean at the filesystem level. Bash is not just a command runner; it is a process and text orchestration language.

;