Skip to content

Instantly share code, notes, and snippets.

@rohan-molloy
Last active October 27, 2019 03:19
Show Gist options
  • Save rohan-molloy/c387eb0111d883527f8132a923232ea1 to your computer and use it in GitHub Desktop.
Save rohan-molloy/c387eb0111d883527f8132a923232ea1 to your computer and use it in GitHub Desktop.
Bash function to read the output of a command into a variable

Bash function to read the output of a command into a variable

readcmd() { 
  varname="$1";
  cmdline="${@:2}";
  read $varname < <($cmdline)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment