What does `declare` do? Name the useful flags.
IntermediateConceptVariables, quoting and expansions
Answer
declare (same as typeset) sets attributes on variables:
-rread-only,-xexport,-iinteger (assignments are evaluated arithmetically)-aindexed array,-Aassociative array-l/-uforce lower/upper case on assignment-nnameref (reference to another variable)-gmake global from inside a function-p NAMEprint the definition,-f NAMEprint a function
declare -r CONFIG=/etc/opskit/opskit.conf
declare -A ports=([http]=80 [https]=443)
declare -p ports
Inside a function, declare behaves like local unless you add -g.
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