Question 15 of 20Pro Only

How do you define and use functions in Bash? How do you pass arguments and return values?

Sample answer preview

Functions in Bash help organize code into reusable blocks. There are two syntaxes for defining them: function greet { echo "Hello, $1" } # Or the POSIX-compatible style: greet() { echo "Hello, $1" } Arguments work just like script arguments.

functionlocal variablesreturnexit codecommand substitutionarguments

Unlock the full answer

Get the complete model answer, key points, common pitfalls, and access to 19+ more DevOps Engineer interview questions.

Upgrade to Pro

Starting at $19/month • Cancel anytime