M
M
Malamut2014-02-25 01:00:23
bash
Malamut, 2014-02-25 01:00:23

What is the data type of [email protected] in BASH?

Slowly I encounter various subtleties of BASH and have reached a dead end. I just can't figure out a simple thing - what is the data type of [email protected] and ${somearray[@]}? More precisely, not even so, the first question is: is it true that [email protected] is completely similar in behavior and usage to ${somearray[@]}? (where somearray is some array).
And the second question, in fact - what data type does [email protected] have and, most importantly, where can I read comprehensive information on how to work with this data type and what does its use in different situations lead to?
Let me explain: there are tricks like ${@: -1}. If [email protected] were a string, then such a construction would return the last character. And it returns the last element of the array, in the case of [email protected] - the last element of a generally non-existent array of all input arguments.
Please clarify what kind of animal this is, how to work with it, and most importantly - what opportunities does it have?
As I understand it, [email protected] is some intermediate pseudo-type, something between an array and a string, which cannot be obtained by external means. [email protected] almost always pretends to be a string of space-separated components, and the only unique property I've found of it is ${@: N} - cutting off the first or last N components. Nothing more intelligible could be dug up / thought up. I really appreciate the help, I would like to understand.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
3
3vi1_0n3, 2014-07-27
@3vi1_0n3

In general, it is rather an untyped array, the value type of any member of which depends on the interpretation. In general, all arrays in bash can be considered untyped.

#!/bin/bash
echo [email protected]
array=()
[email protected]
echo ${array[@]}

If this script is run like this:
this code will output the following:
1 2 3 4 5
1 2 3 4 5

If so:
then the following:
1 2 3 4 5
1 2 3 4 5

As you can see, this is essentially the same thing, although it is represented definitely, it would seem, by numeric values ​​in the first case and string values ​​in the second.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question