Discussion:
Is there a syntax to declare -p $@?
(too old to reply)
Peng Yu
2018-12-04 13:09:42 UTC
Permalink
Hi,

I don't find a way to declare -p $@. Is this possible? Thanks.
--
Regards,
Peng
Grisha Levit
2018-12-04 23:20:09 UTC
Permalink
$ set -- 1 2 3
$ echo ${@@A}
set -- '1' '2' '3'
Peng Yu
2018-12-04 23:30:40 UTC
Permalink
Post by Grisha Levit
$ set -- 1 2 3
set -- '1' '2' '3'
Thanks. It should be double quoted.

$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

set -v
set -- 1 '2 3'
echo ${@@A}
echo "${@@A}"
$ ./main.sh
set -- 1 '2 3'
echo ${@@A}
set -- '1' '2 3'
echo "${@@A}"
set -- '1' '2 3'


Where is it documented?
--
Regards,
Peng
Tadeus Prastowo
2018-12-05 14:40:15 UTC
Permalink
On Wed, Dec 5, 2018 at 12:31 AM Peng Yu <***@gmail.com> wrote:

[...]
Post by Peng Yu
$ ./main.sh
set -- 1 '2 3'
set -- '1' '2 3'
set -- '1' '2 3'
Where is it documented?
https://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion,
particularly as quoted below:

${***@operator}
The expansion is either a transformation of the value of parameter
or information about parameter itself, depending on the value of
operator. Each operator is a single letter:
[...]
A
The expansion is a string in the form of an assignment statement
or declare command that, if evaluated, will recreate parameter with
its attributes and value.
[...]
If parameter is ‘@’ or ‘*’, the operation is applied to each
positional parameter in turn, and the expansion is the resultant list.
[...]
The result of the expansion is subject to word splitting and
pathname expansion as described below.

HTH.

--
Best regards,
Tadeus
Peng Yu
2018-12-05 14:53:12 UTC
Permalink
Post by Tadeus Prastowo
https://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion,
${***@A}
This sounds to be a better replacement for 'declare -p'. Is it?
--
Regards,
Peng
Peng Yu
2018-12-07 04:12:33 UTC
Permalink
Post by Tadeus Prastowo
[...]
Post by Peng Yu
$ ./main.sh
set -- 1 '2 3'
set -- '1' '2 3'
set -- '1' '2 3'
Where is it documented?
https://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion,
The expansion is either a transformation of the value of parameter
or information about parameter itself, depending on the value of
[...]
A
The expansion is a string in the form of an assignment statement
or declare command that, if evaluated, will recreate parameter with
its attributes and value.
[...]
positional parameter in turn, and the expansion is the resultant list.
[...]
The result of the expansion is subject to word splitting and
pathname expansion as described below.
How to understand why `echo ${$@A}` only print an empty line?

$ echo "${$@A}"

$ echo "${$}"
613
$ echo ${$@A}

$ echo ${***@A}
declare -ir BASHPID='440'
--
Regards,
Peng
Dennis Williamson
2018-12-07 04:20:24 UTC
Permalink
Post by Tadeus Prastowo
Post by Tadeus Prastowo
[...]
Post by Peng Yu
$ ./main.sh
set -- 1 '2 3'
set -- '1' '2 3'
set -- '1' '2 3'
Where is it documented?
https://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion
,
Post by Tadeus Prastowo
The expansion is either a transformation of the value of parameter
or information about parameter itself, depending on the value of
[...]
A
The expansion is a string in the form of an assignment statement
or declare command that, if evaluated, will recreate parameter with
its attributes and value.
[...]
positional parameter in turn, and the expansion is the resultant list.
[...]
The result of the expansion is subject to word splitting and
pathname expansion as described below.
$ echo "${$}"
613
declare -ir BASHPID='440'
--
Regards,
Peng
You have too many dollar signs and not enough at signs. Try ${@@A} as Tadeus
posted.
Peng Yu
2018-12-07 04:23:26 UTC
Permalink
On Thu, Dec 6, 2018 at 10:20 PM Dennis Williamson
Post by Peng Yu
Post by Tadeus Prastowo
[...]
Post by Peng Yu
$ ./main.sh
set -- 1 '2 3'
set -- '1' '2 3'
set -- '1' '2 3'
Where is it documented?
https://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion,
The expansion is either a transformation of the value of parameter
or information about parameter itself, depending on the value of
[...]
A
The expansion is a string in the form of an assignment statement
or declare command that, if evaluated, will recreate parameter with
its attributes and value.
[...]
positional parameter in turn, and the expansion is the resultant list.
[...]
The result of the expansion is subject to word splitting and
pathname expansion as described below.
$ echo "${$}"
613
declare -ir BASHPID='440'
--
Regards,
Peng
No. I am referring to a different variable $$ insead of $@.
--
Regards,
Peng
Dennis Williamson
2018-12-07 04:32:00 UTC
Permalink
Post by Peng Yu
On Thu, Dec 6, 2018 at 10:20 PM Dennis Williamson
On Wed, Dec 5, 2018 at 8:40 AM Tadeus Prastowo <
Post by Tadeus Prastowo
[...]
Post by Peng Yu
$ ./main.sh
set -- 1 '2 3'
set -- '1' '2 3'
set -- '1' '2 3'
Where is it documented?
https://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion
,
Post by Tadeus Prastowo
The expansion is either a transformation of the value of parameter
or information about parameter itself, depending on the value of
[...]
A
The expansion is a string in the form of an assignment statement
or declare command that, if evaluated, will recreate parameter with
its attributes and value.
[...]
positional parameter in turn, and the expansion is the resultant list.
[...]
The result of the expansion is subject to word splitting and
pathname expansion as described below.
$ echo "${$}"
613
declare -ir BASHPID='440'
--
Regards,
Peng
Tadeus posted.
--
Regards,
Peng
Why don't you ask about all the special parameters at once. Perhaps the
answer is that only some of them are user settable.
Chet Ramey
2018-12-07 14:23:23 UTC
Permalink
Consider that

1. `$' is a special parameter, not a variable; as such

2. It's not a valid argument to `set', `declare', or an assignment
statement; because

3. It's not user-assignable at all, so there's no way to "recreate the
current value."
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://tiswww.cwru.edu/~chet/
Chris F.A. Johnson
2018-12-05 00:54:53 UTC
Permalink
Hi,
It works as expected for me. What problem are you having?
--
Chris F.A. Johnson, <http://cfajohnson.com>
Peng Yu
2018-12-05 01:45:12 UTC
Permalink
Post by Chris F.A. Johnson
Hi,
It works as expected for me. What problem are you having?
See the reply from Grisha. That is what I would like to have.

`declare -p $@` literally doesn't do so.
--
Regards,
Peng
Loading...