[Bash] function

Zhentiw發表於2024-05-23

Functions in Bash allow you to group commands into reusable blocks. This helps make your scripts more modular and easier to manage.

function_name() {
  commands
}

Example:

#!/bin/zsh

greet() {
  echo "Hello, $1!"
}

greet "Alice"
  • function_name() { commands }: Defines a function.
  • $1: Represents the first argument passed to the function.

相關文章