Array inside an Array: Different syntax for Array in bash
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I found the following example from here. But I can't understand how is array arr
is being defined.
a='domain.de;de;https'
$ arr=($a//;/ )
What is the advantage of defining it like this?
Actually, I want to store an array inside an array of varying size like as follows:
declare -a Workspace=(
"$Folder[0]" "CFD" "General,Markdown"
"$Folder[4]" "GPU" "General,Markdown,Python,C,Java"
)
For example in above, I want to access the terms General
and Markdown
for CFD
.
bash shell-script array gnu bash-array
add a comment |
up vote
0
down vote
favorite
I found the following example from here. But I can't understand how is array arr
is being defined.
a='domain.de;de;https'
$ arr=($a//;/ )
What is the advantage of defining it like this?
Actually, I want to store an array inside an array of varying size like as follows:
declare -a Workspace=(
"$Folder[0]" "CFD" "General,Markdown"
"$Folder[4]" "GPU" "General,Markdown,Python,C,Java"
)
For example in above, I want to access the terms General
and Markdown
for CFD
.
bash shell-script array gnu bash-array
1
Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
– Jeff Schaller
Nov 22 at 0:44
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I found the following example from here. But I can't understand how is array arr
is being defined.
a='domain.de;de;https'
$ arr=($a//;/ )
What is the advantage of defining it like this?
Actually, I want to store an array inside an array of varying size like as follows:
declare -a Workspace=(
"$Folder[0]" "CFD" "General,Markdown"
"$Folder[4]" "GPU" "General,Markdown,Python,C,Java"
)
For example in above, I want to access the terms General
and Markdown
for CFD
.
bash shell-script array gnu bash-array
I found the following example from here. But I can't understand how is array arr
is being defined.
a='domain.de;de;https'
$ arr=($a//;/ )
What is the advantage of defining it like this?
Actually, I want to store an array inside an array of varying size like as follows:
declare -a Workspace=(
"$Folder[0]" "CFD" "General,Markdown"
"$Folder[4]" "GPU" "General,Markdown,Python,C,Java"
)
For example in above, I want to access the terms General
and Markdown
for CFD
.
bash shell-script array gnu bash-array
bash shell-script array gnu bash-array
edited Nov 22 at 0:28
asked Nov 22 at 0:19
Nikhil
20919
20919
1
Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
– Jeff Schaller
Nov 22 at 0:44
add a comment |
1
Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
– Jeff Schaller
Nov 22 at 0:44
1
1
Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
– Jeff Schaller
Nov 22 at 0:44
Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
– Jeff Schaller
Nov 22 at 0:44
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
An array of arrays is a bad idea in shell (any shell). You need some other language.
how is array
arr
being defined.?a='domain.de;de;https'
arr=($a//;/ )
It works by:
- replacing every
;
by anspace
- Assuming IFS is space, tab, newline (the default)
- splitting on space (included in IFS) the unquoted expansion of
$...
- assigning it to an array
(...)
- and naming that array
arr=
.
What is the advantage of defining it like this?
None, only problems:
- If any of the elements contains an space, a tab or a newline, it will be split.
- As globbing was not turn off, any
*
,?
or[ ]
will be expanded to matching files. - If nullglob is active, any string containing
*
,?
or[ ]
will be removed. - if failglob is active any of the previous characters will generate an error.
In short, splitting on the shell is full of gotchas.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
An array of arrays is a bad idea in shell (any shell). You need some other language.
how is array
arr
being defined.?a='domain.de;de;https'
arr=($a//;/ )
It works by:
- replacing every
;
by anspace
- Assuming IFS is space, tab, newline (the default)
- splitting on space (included in IFS) the unquoted expansion of
$...
- assigning it to an array
(...)
- and naming that array
arr=
.
What is the advantage of defining it like this?
None, only problems:
- If any of the elements contains an space, a tab or a newline, it will be split.
- As globbing was not turn off, any
*
,?
or[ ]
will be expanded to matching files. - If nullglob is active, any string containing
*
,?
or[ ]
will be removed. - if failglob is active any of the previous characters will generate an error.
In short, splitting on the shell is full of gotchas.
add a comment |
up vote
1
down vote
An array of arrays is a bad idea in shell (any shell). You need some other language.
how is array
arr
being defined.?a='domain.de;de;https'
arr=($a//;/ )
It works by:
- replacing every
;
by anspace
- Assuming IFS is space, tab, newline (the default)
- splitting on space (included in IFS) the unquoted expansion of
$...
- assigning it to an array
(...)
- and naming that array
arr=
.
What is the advantage of defining it like this?
None, only problems:
- If any of the elements contains an space, a tab or a newline, it will be split.
- As globbing was not turn off, any
*
,?
or[ ]
will be expanded to matching files. - If nullglob is active, any string containing
*
,?
or[ ]
will be removed. - if failglob is active any of the previous characters will generate an error.
In short, splitting on the shell is full of gotchas.
add a comment |
up vote
1
down vote
up vote
1
down vote
An array of arrays is a bad idea in shell (any shell). You need some other language.
how is array
arr
being defined.?a='domain.de;de;https'
arr=($a//;/ )
It works by:
- replacing every
;
by anspace
- Assuming IFS is space, tab, newline (the default)
- splitting on space (included in IFS) the unquoted expansion of
$...
- assigning it to an array
(...)
- and naming that array
arr=
.
What is the advantage of defining it like this?
None, only problems:
- If any of the elements contains an space, a tab or a newline, it will be split.
- As globbing was not turn off, any
*
,?
or[ ]
will be expanded to matching files. - If nullglob is active, any string containing
*
,?
or[ ]
will be removed. - if failglob is active any of the previous characters will generate an error.
In short, splitting on the shell is full of gotchas.
An array of arrays is a bad idea in shell (any shell). You need some other language.
how is array
arr
being defined.?a='domain.de;de;https'
arr=($a//;/ )
It works by:
- replacing every
;
by anspace
- Assuming IFS is space, tab, newline (the default)
- splitting on space (included in IFS) the unquoted expansion of
$...
- assigning it to an array
(...)
- and naming that array
arr=
.
What is the advantage of defining it like this?
None, only problems:
- If any of the elements contains an space, a tab or a newline, it will be split.
- As globbing was not turn off, any
*
,?
or[ ]
will be expanded to matching files. - If nullglob is active, any string containing
*
,?
or[ ]
will be removed. - if failglob is active any of the previous characters will generate an error.
In short, splitting on the shell is full of gotchas.
answered Nov 22 at 0:44
Isaac
9,72811445
9,72811445
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483331%2farray-inside-an-array-different-syntax-for-array-in-bash%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
– Jeff Schaller
Nov 22 at 0:44