What is the difference between `$( < file )` and `$(cat file)`?
BeginnerConceptVariables, quoting and expansions
Answer
Both read the whole file into a string with trailing newlines stripped. $(< file) is a Bash shortcut that reads the file without forking cat, so it is faster in loops. If the file is missing, both print an error; $(< file) fails with bash: file: No such file or directory.
token=$(< /run/secrets/api_token)
More on Variables, quoting and expansions
What are the rules for assigning variables in Bash?BeginnerWhat is the difference between single quotes, double quotes and `$'...'`?BeginnerWhy should you almost always quote variable expansions? Show what goes wrong.BeginnerExplain the difference between `"$@"`, `"$*"`, `$@` and `$*`.IntermediateWhat do `${var:-default}`, `${var:=default}`, `${var:+alt}` and `${var:?msg}` do?IntermediateHow do you strip prefixes and suffixes with parameter expansion?Intermediate