Skip to main content

1.7 The Shell

Stage I: The Substrate

"The GUI is for the user. The Shell is for the Admin. The Robot is an Admin of its own soul."

1. Streams (The Plumbing)​

Every process is born with three pipes attached to its face:

  1. stdin (0): Data flowing in.
  2. stdout (1): Data flowing out (Success).
  3. stderr (2): Data flowing out (Panic).

Piping (|): Connects the stdout of Process A to the stdin of Process B. cat sensor_log.txt | grep "ERROR" | wc -l This is a Dataflow Architecture. It is the ancestor of ROS Topics.


2. Environment Variables (Context Injection)​

How does a process know where it is? Env Vars are global variables inherited from the parent shell. PATH, ROS_DOMAIN_ID, LD_LIBRARY_PATH. They effectively set the "Global Configuration" for the process's life.


3. Shell as a Language​

Bash has loops, conditionals, and functions. It is Turing Complete. It is the glue language of DevOps.

The Shebang (#!)​

#!/usr/bin/env python3 This magic line tells the Kernel's program loader (execve): "Do not run this text file as machine code. Run this interpreter and feed the file to it."


Deep FAQ​

Q: What is source ~/.bashrc? A: bashrc is a script that runs every time a new shell starts. source executes the script in the current shell process. If you ran ./script.sh, it would spawn a generic child shell, set variables there, and die. The parent shell would learn nothing. source injects the variables into you.

Q: logic of && and ||? A: Short-circuit logic. make && make install: Only install if make succeeds (exit code 0). test || exit: Exit if test fails (exit code non-zero).