PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Table of Contents

Bash Functions

Functions are a great way to reuse code. The structure of a function in bash is quite similar to most languages:

function function_name() {
    your_commands
}

You can also omit the function keyword in the beginning which would also work:

function_name() {
    your_commands
}

I prefer putting it there for better readability.

Example of a "Hello World!" function:

#!/bin/bash

function hello(){
    echo "Hello World Function!"
}

hello

One thing to keep in mind is that when you call the function, you should not add the parenthesis.

Passing arguments to a function works in the same way as passing arguments to a script:

#!/bin/bash

function hello(){
    echo "Hello $1!"
}

hello DevDojo