1

I'm wondering if there's some command that takes in a variable as an argument, and echoes all of its attributes (integer, array, readonly, etc)

2
  • 2
    Your "side question" should be asked separately. Putting more than one distinct topic in a question makes it hard to judge which answer is most correct, and introduces corner cases that make site rules (around voting, duplicate management, &c) hard to handle; that's part of why "Too Broad" is a close reason. Commented Oct 3, 2017 at 23:16
  • 1
    (also, filesystem utilities -- particularly including those such as lsattr and stat, or extended versions of find capable of metadata lookup -- aren't part of bash, but are provided by your operating system, so they'd need to be asked with a different set of tags). Commented Oct 3, 2017 at 23:20

2 Answers 2

3

I think

$ declare -p var

is what you are looking for:

From help declare:

declare: declare [-aAfFgilnrtux] [-p] [name[=value] ...]
...
-p  display the attributes and value of each NAME
Sign up to request clarification or add additional context in comments.

Comments

2

Use ${variable@a}. For example:

$ declare -ai X=(1 2 3)
$ echo ${X@a}
ai

Thanks to user "F. Hauri - Give Up GitHub"; I found that notation in their answer to this unrelated question: Unset readonly variable in bash

Here is how to get the flags for variable if you have its name in another variable.

$ S="X"
$ echo ${!S@a}
ai

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.