Skip to content

Instantly share code, notes, and snippets.

@fearphage
Created July 10, 2019 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fearphage/e6f0a16ec43ab42cab140ba67ac123e3 to your computer and use it in GitHub Desktop.
Save fearphage/e6f0a16ec43ab42cab140ba67ac123e3 to your computer and use it in GitHub Desktop.
Does mapfile work on a mac?
#!/usr/bin/env bash
mapfile -t meh < <(ps -ax)
echo "found ${#meh[@]} processes"
@fearphage
Copy link
Author

The answer is no. mapfile is a feature of Bash 4.0. Macs currently are still on 3.x.

Here is the alternative:

declare -a meh

while IFS= read -r line; do meh+=("$line"); done < <(ps -ax)

echo "found ${#meh[@]} processes"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment