Nick Janetakis 3/31/2026

Bash Nameref: Mutate Function Arguments (Pointer-Like Behavior)

Read Original

This article covers Bash's nameref feature (local -n) introduced in Bash 4.3, which allows functions to mutate variables passed by name, similar to pointers. It includes a TL;DR, use case example from dotfiles for skipping package installations, and warnings about circular name references. The technique helps avoid subshells and global variables, especially when returning arrays. Targeted at shell scripters looking for advanced Bash techniques.

Bash Nameref: Mutate Function Arguments (Pointer-Like Behavior)

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

No top articles yet