What type of operation is /#/- in â$my_array[@]/#/-â?

Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
The accepted answer to Transform an array into arguments of a command? uses the following Bash command:
command "$my_array[@]/#/-" "$1"
I'm trying to figure out what the /#/- part does, exactly. Unfortunately, I don't know what to call it, so I'm having trouble finding any documentation. I've looked through the Bash man page section on arrays and a few websites, but can't find anything.
bash array
New contributor
Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
4
down vote
favorite
The accepted answer to Transform an array into arguments of a command? uses the following Bash command:
command "$my_array[@]/#/-" "$1"
I'm trying to figure out what the /#/- part does, exactly. Unfortunately, I don't know what to call it, so I'm having trouble finding any documentation. I've looked through the Bash man page section on arrays and a few websites, but can't find anything.
bash array
New contributor
Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
The accepted answer to Transform an array into arguments of a command? uses the following Bash command:
command "$my_array[@]/#/-" "$1"
I'm trying to figure out what the /#/- part does, exactly. Unfortunately, I don't know what to call it, so I'm having trouble finding any documentation. I've looked through the Bash man page section on arrays and a few websites, but can't find anything.
bash array
New contributor
Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The accepted answer to Transform an array into arguments of a command? uses the following Bash command:
command "$my_array[@]/#/-" "$1"
I'm trying to figure out what the /#/- part does, exactly. Unfortunately, I don't know what to call it, so I'm having trouble finding any documentation. I've looked through the Bash man page section on arrays and a few websites, but can't find anything.
bash array
bash array
New contributor
Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 51 mins ago
Justin
1233
1233
New contributor
Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Justin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
7
down vote
accepted
This is an instance of pattern replacement in shell parameter expansion: $parameter/pattern/replacement expands $parameter, replacing the first instance of pattern with replacement. In the context of a pattern of this kind, # is special: it anchors the pattern to the start of the parameter. The end result of all this is to expand all the values in the my_array array, prepending - to each one (by replacing the empty pattern at the start of each parameter).
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
This is an instance of pattern replacement in shell parameter expansion: $parameter/pattern/replacement expands $parameter, replacing the first instance of pattern with replacement. In the context of a pattern of this kind, # is special: it anchors the pattern to the start of the parameter. The end result of all this is to expand all the values in the my_array array, prepending - to each one (by replacing the empty pattern at the start of each parameter).
add a comment |Â
up vote
7
down vote
accepted
This is an instance of pattern replacement in shell parameter expansion: $parameter/pattern/replacement expands $parameter, replacing the first instance of pattern with replacement. In the context of a pattern of this kind, # is special: it anchors the pattern to the start of the parameter. The end result of all this is to expand all the values in the my_array array, prepending - to each one (by replacing the empty pattern at the start of each parameter).
add a comment |Â
up vote
7
down vote
accepted
up vote
7
down vote
accepted
This is an instance of pattern replacement in shell parameter expansion: $parameter/pattern/replacement expands $parameter, replacing the first instance of pattern with replacement. In the context of a pattern of this kind, # is special: it anchors the pattern to the start of the parameter. The end result of all this is to expand all the values in the my_array array, prepending - to each one (by replacing the empty pattern at the start of each parameter).
This is an instance of pattern replacement in shell parameter expansion: $parameter/pattern/replacement expands $parameter, replacing the first instance of pattern with replacement. In the context of a pattern of this kind, # is special: it anchors the pattern to the start of the parameter. The end result of all this is to expand all the values in the my_array array, prepending - to each one (by replacing the empty pattern at the start of each parameter).
edited 36 mins ago
answered 43 mins ago
Stephen Kitt
148k22325393
148k22325393
add a comment |Â
add a comment |Â
Justin is a new contributor. Be nice, and check out our Code of Conduct.
Justin is a new contributor. Be nice, and check out our Code of Conduct.
Justin is a new contributor. Be nice, and check out our Code of Conduct.
Justin is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472991%2fwhat-type-of-operation-is-in-my-array%23new-answer', 'question_page');
);
Post as a guest
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
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
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
