Pemako Documentation

website·Indexed 29 days ago

https://pemako.cn

A collection of technical notes and guides focusing on GNU Bash, including detailed explanations of shell built-ins like shopt, set, declare, and trap, parameter expansion, job control, and POSIX standards. The site also includes a source-level analysis of z.sh and general technical blog posts on AI model basics and terminal configurations.

Tokens
38.2K
Snippets
245
Records
292
Agent score
47%

What's inside Pemako

  1. Overview of the Bash set command

    The set command is a core Bash built-in used for three primary purposes: controlling shell behavior options (e.g., error handling, debugging), overriding positional parameters ($1, $2, etc.), and inspecting the current shell state. Unlike shopt, which handles Bash-specific extensions like globbing and completion, set follows POSIX standards and is available across all POSIX shells.
  2. Overview of the bind command

    bind is used to configure Readline key bindings and variables for interactive Bash command-line editing. Readline is the underlying library responsible for cursor movement, history, and completion. Changes made via bind take effect immediately without requiring a shell restart, providing the same functionality as editing the ~/.inputrc file.
  3. Overview of the POSIX Standard

    POSIX (Portable Operating System Interface), formally known as IEEE Std 1003, is a set of standards defined by the IEEE to ensure software portability across different Unix-like operating systems. It acts as a contract: any system that implements POSIX allows programs written to the standard to run across platforms.
  4. Understand AI model weights and quantization

    Weights are the billions of decimal numbers (parameters) that store a model's learned knowledge (grammar, logic, etc.). Quantization is the process of reducing the precision of these weights to shrink the model file size and increase execution speed, though it may introduce slight quality loss.

    Common quantization levels:

    • F16: 16-bit (Original precision, largest file)
    • Q8: 8-bit (Slight loss)
    • Q4: 4-bit (Significant compression, acceptable quality)
    • Q2: 2-bit (Rough, high quality loss)
  5. Bash Specification and POSIX Compliance

    Bash is a superset of POSIX sh. In cases of conflict, Bash follows POSIX standards rather than traditional sh behavior. Unlike SVR4.2 sh, which only supports single-character options (e.g., -xv), Bash supports multi-character startup options such as --noediting and --dump-strings. It also provides a more robust Restricted mode (rbash).
  6. Understand Model Weights and Memory Requirements

    Model weights are the billions of decimal numbers adjusted during training that store the model's knowledge, including grammar, common sense, and logic. The model size (e.g., '4B' in Qwen3-4B) refers to the number of weights (4 billion). In original FP16 precision, each weight requires 2 bytes, meaning a 4B parameter model requires approximately 8GB of storage space.
  7. Read input from standard input or file descriptors

    The read command reads a line from standard input (or a specified file descriptor), splits it based on the Internal Field Separator (IFS), and assigns the results to variables. If no variable names are provided, the entire line is assigned to the built-in variable $REPLY.
    read [-Eers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
  8. Use shopt to manage Bash extended shell options

    The shopt command is used to enable or disable extended shell behaviors in Bash. It allows for more flexible globbing, directory navigation, and script execution logic. Unlike set -o, which handles POSIX standard options, shopt is specific to Bash extensions.
    shopt -s option_name  # Enable an option
    shopt -u option_name  # Disable an option
    shopt -q option_name  # Check if an option is set (returns 0 if set)
    shopt                # List all available options and their current status
  9. Inspect variable attributes and formats using @

    The @ operator provides various transformations and metadata about a variable, such as its declare attributes or quoted formatting.
    # @a: Show attribute flags
    declare -r PI=3.14
    echo ${PI@a}       # Output: r (read-only)
    
    declare -i num=10
    echo ${num@a}      # Output: i (integer)
    
    declare -A map
    echo ${map@a}      # Output: A (associative array)
    
    # Other @ operators:
    # @Q: Quote the value (escaped)
    # @E: Expand escape sequences
    # @P: Expand as a prompt string
    # @A: Generate the declare statement
    # @U: Convert to uppercase
    # @L: Convert to lowercase
  10. Manage Bash extended behaviors with shopt

    shopt (shell options) is a Bash-specific command used to enable or disable extended shell behavior features. Unlike set, which manages POSIX standard shell behaviors (e.g., -e for error exit), shopt focuses on Bash-specific extensions such as advanced globbing, history management, and interactive enhancements.
  11. z.sh Design Philosophy and Engineering Decisions

    The core value of z is to replace rigid alphabetical directory matching with 'frecency' (frequency + recency). To achieve this, the following engineering decisions were made:

    • Storage: Uses a single plain text file (~/.z) for zero dependencies, easy migration, and user-led backups.
    • Performance: Uses awk for data processing to achieve O(N) scanning and avoid slow shell loops.
    • Concurrency: Writes to a temporary file and then uses mv for atomic replacement to prevent data corruption during crashes or concurrent writes.
    • Responsiveness: Uses precmd with background asynchronous writes (via subshells) to avoid blocking the interactive shell.
    • Maintenance: Implements an 'aging' mechanism to prevent the data file from growing indefinitely and allow new habits to override old ones.
    • Compatibility: Avoids bash-specific features to maintain compatibility across both bash and zsh.
  12. Understand Bash Job concepts and states

    In Bash, every pipeline executed creates a process group, which is treated as a single job. The shell maintains a jobs table to track these. Jobs can be in three states:

    • Foreground: Occupies the terminal; the shell waits for it to complete.
    • Background: Started by adding & to the end of a command; returns the prompt immediately.
    • Stopped/Suspended: Suspended via Ctrl-Z (sends SIGTSTP), Ctrl-C (sends SIGINT), or Ctrl-\ (sends SIGQUIT).