bash_reserved_words

Bash Reserved Words

Also called: Bash Keywords, Bash Language Keywords, Bash Reserved Words, Bash Reserved Keywords, Bash Reserved Identifiers

Return to Reserved keywords, Reserved words, Reserved identifier, Keywords, Bash, Bash DevOps - Bash SRE - Bash CI/CD, Cloud Native Bash - Bash Microservices - Serverless Bash, Bash Security - Bash DevSecOps, Functional Bash, Bash Concurrency, Bash Data Science - Bash and Databases, Bash Machine Learning, Bash Bibliography, Bash Courses, Bash Glossary, Awesome Bash, Bash GitHub, Bash Topics

Like any programming language, the Bash language designates certain words that the Bash interpreter (the specific Linux shell or Unix shell) recognizes as special words. For that reason, you're not allowed to use them for naming your Bash constructs. The list of Bash reserved words (also called Bash keywords) is surprisingly short:

Reserved words are words that have special meaning to the shell. They are used to begin and end the shell’s compound commands.


Creating a glossary of Bash reserved words sorted by their frequency of use is somewhat subjective, as it depends on what kinds of scripts are being written. Common scripting tasks often involve iteration, conditionals, and defining functions, which will guide our list of commonly used reserved words. Here's an attempt to outline these, formatted in MediaWiki markup:

```mediawiki

Bash Reserved Words Glossary

This glossary lists Bash reserved words that are frequently used in shell scripting. Each entry includes a brief code example to illustrate its usage.

if

The `if` statement is used to execute commands based on a condition.

if [ "$a" -eq "$b" ]; then
    echo "a equals b"
fi

else

The `else` statement is used to execute commands if the `if` condition is false.

if [ "$a" -eq "$b" ]; then
    echo "a equals b"
else
    echo "a does not equal b"
fi

elif

The `elif` (else if) statement allows for multiple conditions.

if [ "$a" -eq "$b" ]; then
    echo "a equals b"
elif [ "$a" -gt "$b" ]; then
    echo "a is greater than b"
else
    echo "a is less than b"
fi

for

The `for` loop is used to iterate over a series of values.

for i in 1 2 3; do
    echo "$i"
done

while

The `while` loop executes as long as a condition is true.

while [ "$a" -lt 10 ]; do
    echo "$a"
    a=$((a + 1))
done

do

The `do` keyword is used with loops (`for`, `while`, `until`) to start the execution block.

for i in 1 2 3; do
    echo "$i"
done

done

The `done` keyword is used to end a loop (`for`, `while`, `until`).

while [ "$a" -lt 10 ]; do
    echo "$a"
    a=$((a + 1))
done

function

The `function` keyword is used to define a function.

function my_func() {
    echo "Hello World"
}

case

The `case` statement allows branching based on patterns.

case "$1" in
    start)
        echo "Starting"
        ;;
    stop)
        echo "Stopping"
        ;;
    *)
        echo "Usage: $0 start|stop"
        ;;
esac

esac

The `esac` keyword is used to end a `case` statement.

case "$1" in
    start|stop) echo "Will start or stop" ;;
    *) echo "Unknown command" ;;
esac

in

The `in` keyword is used with `case` and `for` statements to specify a list.

for i in $(seq 1 3); do
    echo "$i"
done

until

The `until` loop is used to execute commands until a condition is true.

until [ "$a" -ge 10 ]; do
    echo "$a"
    a=$((a + 1))
done

select

The `select` statement is used to generate a menu from a list of items.

select choice in "Option 1" "Option 2" "Option 3"; do
    case $REPLY in
        1) echo "Selected Option 1"; break ;;
        2) echo "Selected Option 2"; break ;;
        3) echo "Selected Option 3"; break ;;
        *) echo "Invalid selection"; break ;;
    esac
done

This list includes some of the most commonly used Bash reserved words, ideal for beginners and those looking to understand shell scripting better. Bash scripting allows for complex flow control, function definitions, and system automation with these and other reserved words. ```

This format is designed for easy inclusion in a MediaWiki-based site, offering clear examples and explanations to help readers quickly understand the use of each reserved word in Bash scripting.


The following words are recognized as reserved when unquoted and the first word of a command (see below for exceptions):

{ } bash_reserved_words !

in is recognized as a reserved word if it is the third word of a case or select command. in and do are recognized as reserved words if they are the third word in a for command.

https://www.gnu.org/software/bash/manual/html_node/Reserved-Words.html

Research More

Fair Use Sources

Bash: Bash Fundamentals, Bash Inventor - Bash Language Designer: Brian Fox on June 8, 1989 at urging of Richard Stallman of Free Software Foundation (FSF); Chet Ramey is now the maintainer. Bash Scripting, Bash DevOps - Bash SRE, Cloud Native Bash (Bash on Kubernetes - Bash on AWS - Bash on Azure - Bash on GCP), Bash Microservices, Bash Containerization (Bash Docker - Bash on Docker Hub), Serverless Bash, Bash Data Science - Bash DataOps - Bash and Databases (Bash ORM), Bash ML - Bash DL, Functional Bash (1. Bash Immutability, 2. Bash Purity - Bash No Side-Effects, 3. Bash First-Class Functions - Bash Higher-Order Functions, Bash Lambdas - Bash Anonymous Functions - Bash Closures, Bash Lazy Evaluation, 4. Bash Recursion), Reactive Bash), Bash Concurrency - Bash Parallel Programming - Async Bash, Bash Networking, Bash Security - Bash DevSecOps - Bash OAuth, Bash Memory Allocation (Bash Heap - Bash Stack - Bash Garbage Collection), Bash CI/CD - Bash Dependency Management - Bash DI - Bash IoC - Bash Build Pipeline, Bash Automation - Bash Scripting, Bash Package Managers, Bash Modules - Bash Packages, Bash Installation (Bash Windows - Chocolatey Bash, Bash macOS - Homebrew Bash, Bash on Linux), Bash Configuration, Bash Observability (Bash Monitoring, Bash Performance - Bash Logging), Bash Language Spec - Bash RFCs - Bash Roadmap, Bash Keywords, Bash Operators, Bash Functions, Bash Data Structures - Bash Algorithms, Bash Syntax, Bash OOP (1. Bash Encapsulation - 2. Bash Inheritance - 3. Bash Polymorphism - 4. Bash Abstraction), Bash Design Patterns - Bash Best Practices - Bash Style Guide - Clean Bash - Bash BDD, Bash Generics, Bash I/O, Bash Serialization - Bash Deserialization, Bash APIs, Bash REST - Bash JSON - Bash GraphQL, Bash gRPC, Bash Virtualization, Bash Development Tools: Bash SDK, Bash Compiler - Bash Transpiler, Bash Interpreter - Bash REPL, Bash IDEs (JetBrains Bash, Bash Visual Studio Code), Bash Linter, Bash Community - Bashaceans - Bash User, Bash Standard Library - Bash Libraries - Bash Frameworks, Bash Testing - Bash TDD, Bash History, Bash Research, Bash Topics, Bash Uses - List of Bash Software - Written in Bash - Bash Popularity, Bash Bibliography - Bash Courses, Bash Glossary - Bash Official Glossary, Bash GitHub, Awesome Bash. (navbar_bash)



© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers

SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.


bash_reserved_words.txt · Last modified: 2024/04/28 03:13 (external edit)