Code Monkey home page Code Monkey logo

bash-scripting-basics's Introduction


Bash Scripting Basics

This README provides an introduction to the fundamentals of Bash scripting, covering essential concepts and syntax to help you write and understand Bash scripts.

Table of Contents

Overview

Bash (Bourne Again SHell) is a widely-used shell and command language interpreter in Unix and Linux operating systems. Bash scripts are sequences of commands written in the Bash language and executed in a Bash environment.

This README provides a basic understanding of Bash scripting, covering key aspects such as script structure, syntax, variables, conditionals, loops, functions, and how to run a Bash script.

Script Structure

A Bash script typically follows this structure:

#!/bin/bash

# Your script commands here
# ...

Shebang

The #!/bin/bash line, known as the shebang, tells the system to use Bash to interpret the script.

Comments

Comments in Bash start with # and are used to annotate the script with human-readable information. Comments are ignored during script execution.

Variables

Variables in Bash are assigned using the syntax variable_name=value. Example:

greeting="Hello, World!"
echo $greeting

Conditional Statements

  • If-else statement:

    if [ condition ]; then
        # commands if condition is true
    else
        # commands if condition is false
    fi
  • Case statement:

    case $variable in
        pattern1)
            # commands for pattern1
            ;;
        pattern2)
            # commands for pattern2
            ;;
        *)
            # default commands
            ;;
    esac

Loops

  • For loop:

    for i in {1..5}; do
        # commands
    done
  • While loop:

    while [ condition ]; do
        # commands
    done

Functions

Functions in Bash are defined and called using the following syntax:

function_name() {
    # function body
}

# Call the function
function_name

Running a Bash Script

  1. Make the script executable:

    chmod +x script_name.sh
  2. Run the script:

    ./script_name.sh

Contributing

Contributions and feedback are welcome! Feel free to open issues or submit pull requests if you have any suggestions or improvements.

License

This project is licensed under the MIT License.


bash-scripting-basics's People

Contributors

bihansamarasinghe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.