Add prefix and suffix to $@ in bash
How to add suffix and prefix to $@
?
If I do $PREFIX/$@/$SUFFIX
, I get the prefix and the suffix only in the first parameter.
bash
add a comment |
How to add suffix and prefix to $@
?
If I do $PREFIX/$@/$SUFFIX
, I get the prefix and the suffix only in the first parameter.
bash
1
You will have to iterate over array and add prefix and suffix to each entry.
– Sameer Naik
Jul 25 '16 at 1:10
Are you looking to add a prefix an suffix to every argument, or add new prefix and suffix arguments on either side of the set of existing arguments? E.g. if your prefix isP
and your suffix isS
and$@
is1 2 3
are you looking forP1S P2S P3S
orP 1 2 3 S
?
– dimo414
Jul 25 '16 at 1:42
1
I'm looking forP1S P2S P3S
– Richard
Jul 25 '16 at 1:44
add a comment |
How to add suffix and prefix to $@
?
If I do $PREFIX/$@/$SUFFIX
, I get the prefix and the suffix only in the first parameter.
bash
How to add suffix and prefix to $@
?
If I do $PREFIX/$@/$SUFFIX
, I get the prefix and the suffix only in the first parameter.
bash
bash
edited Jul 25 '16 at 6:31
heemayl
20.9k12135
20.9k12135
asked Jul 25 '16 at 1:06
RichardRichard
599522
599522
1
You will have to iterate over array and add prefix and suffix to each entry.
– Sameer Naik
Jul 25 '16 at 1:10
Are you looking to add a prefix an suffix to every argument, or add new prefix and suffix arguments on either side of the set of existing arguments? E.g. if your prefix isP
and your suffix isS
and$@
is1 2 3
are you looking forP1S P2S P3S
orP 1 2 3 S
?
– dimo414
Jul 25 '16 at 1:42
1
I'm looking forP1S P2S P3S
– Richard
Jul 25 '16 at 1:44
add a comment |
1
You will have to iterate over array and add prefix and suffix to each entry.
– Sameer Naik
Jul 25 '16 at 1:10
Are you looking to add a prefix an suffix to every argument, or add new prefix and suffix arguments on either side of the set of existing arguments? E.g. if your prefix isP
and your suffix isS
and$@
is1 2 3
are you looking forP1S P2S P3S
orP 1 2 3 S
?
– dimo414
Jul 25 '16 at 1:42
1
I'm looking forP1S P2S P3S
– Richard
Jul 25 '16 at 1:44
1
1
You will have to iterate over array and add prefix and suffix to each entry.
– Sameer Naik
Jul 25 '16 at 1:10
You will have to iterate over array and add prefix and suffix to each entry.
– Sameer Naik
Jul 25 '16 at 1:10
Are you looking to add a prefix an suffix to every argument, or add new prefix and suffix arguments on either side of the set of existing arguments? E.g. if your prefix is
P
and your suffix is S
and $@
is 1 2 3
are you looking for P1S P2S P3S
or P 1 2 3 S
?– dimo414
Jul 25 '16 at 1:42
Are you looking to add a prefix an suffix to every argument, or add new prefix and suffix arguments on either side of the set of existing arguments? E.g. if your prefix is
P
and your suffix is S
and $@
is 1 2 3
are you looking for P1S P2S P3S
or P 1 2 3 S
?– dimo414
Jul 25 '16 at 1:42
1
1
I'm looking for
P1S P2S P3S
– Richard
Jul 25 '16 at 1:44
I'm looking for
P1S P2S P3S
– Richard
Jul 25 '16 at 1:44
add a comment |
3 Answers
3
active
oldest
votes
I would use shell [ parameter expansion ] for this
$ set -- one two three
$ echo "$@"
one two three
$ set -- "${@/#/pre}" && set -- "${@/%/post}"
$ echo "$@"
preonepost pretwopost prethreepost
Notes
- The
#
matches the beginning - The
%
matches the end - Using double quotes around
${@}
considers each element as a separate word. so replacement happens for every positional parameter
2
This is nice and compact. The OP should consider making this the accepted solution.
– John1024
Jul 25 '16 at 2:54
add a comment |
Let's create a parameters for test purposes:
$ set -- one two three
$ echo "$@"
one two three
Now, let's use bash to add prefixes and suffixes:
$ IFS=$'n' a=($(printf "pre/%s/postn" "$@"))
$ set -- "${a[@]}"
$ echo -- "$@"
pre/one/post pre/two/post pre/three/post
Limitations: (a) since this uses newline-separated strings, it won't work if your $@
contains newlines itself. In that case, there may be another choice for IFS
that would suffice. (b) This is subject to globbing. If either of these is an issue, see the more general solution below.
On the other hand, if the positional parameters do not contain whitespace, then no change to IFS
is needed.
Also, if IFS
is changed, then one may want to save IFS
beforehand and restore afterward.
More general solution
If we don't want to make any assumptions about whitespace, we can modify "$@" with a loop:
$ a=(); for p in "$@"; do a+=("pre/$p/post"); done
$ set -- "${a[@]}"
$ echo "$@"
pre/one/post pre/two/post pre/three/post
Why do we need to change IFS here? I tried without it seems to work
– Richard
Jul 25 '16 at 1:23
What it the magic behind this set?
– Richard
Jul 25 '16 at 1:26
4
@Richard It is only important to change IFS if you have spaces or tabs in your parameters. Otherwise, it is not needed.set
is a shell builtin that, among other things, sets the positional parameters.
– John1024
Jul 25 '16 at 1:35
1
@John1024:a=( $(echo '*') ); declare -p a
. The output from the command substitution is subject to globbing.
– mklement0
Jul 25 '16 at 2:16
1
@mklement0 OK. Thanks. I updated the answer to note that that issue applies to the first approach.
– John1024
Jul 25 '16 at 2:22
|
show 2 more comments
Note: This is essentially a slightly more detailed version of sjam's answer.
John1024's answer is helpful, but:
- requires a subshell (which involves a child process)
- can result in unwanted globbing applied to the array elements.
Fortunately, Bash parameter expansion can be applied to arrays too, which avoids these issues:
set -- 'one' 'two' # sample input array, which will be reflected in $@
# Copy $@ to new array ${a[@]}, adding a prefix to each element.
# `/#` replaces the string that follows, up to the next `/`,
# at the *start* of each element.
# In the absence of a string, the replacement string following
# the second `/` is unconditionally placed *before* each element.
a=( "${@/#/PREFIX}" )
# Add a suffix to each element of the resulting array ${a[@]}.
# `/%` replaces the string that follows, up to the next `/`,
# at the *end* of each element.
# In the absence of a string, the replacement string following
# the second `/` is unconditionally placed *after* each element.
a=( "${a[@]/%/SUFFIX}" )
# Print the resulting array.
declare -p a
This yields:
declare -a a='([0]="PREFIXoneSUFFIX" [1]="PREFIXtwoSUFFIX")'
Note that double-quoting the array references is crucial to protect their elements from potential word-splitting and globbing (filename expansion) - both of which are instances of shell expansions.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2fstackoverflow.com%2fquestions%2f38558401%2fadd-prefix-and-suffix-to-in-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would use shell [ parameter expansion ] for this
$ set -- one two three
$ echo "$@"
one two three
$ set -- "${@/#/pre}" && set -- "${@/%/post}"
$ echo "$@"
preonepost pretwopost prethreepost
Notes
- The
#
matches the beginning - The
%
matches the end - Using double quotes around
${@}
considers each element as a separate word. so replacement happens for every positional parameter
2
This is nice and compact. The OP should consider making this the accepted solution.
– John1024
Jul 25 '16 at 2:54
add a comment |
I would use shell [ parameter expansion ] for this
$ set -- one two three
$ echo "$@"
one two three
$ set -- "${@/#/pre}" && set -- "${@/%/post}"
$ echo "$@"
preonepost pretwopost prethreepost
Notes
- The
#
matches the beginning - The
%
matches the end - Using double quotes around
${@}
considers each element as a separate word. so replacement happens for every positional parameter
2
This is nice and compact. The OP should consider making this the accepted solution.
– John1024
Jul 25 '16 at 2:54
add a comment |
I would use shell [ parameter expansion ] for this
$ set -- one two three
$ echo "$@"
one two three
$ set -- "${@/#/pre}" && set -- "${@/%/post}"
$ echo "$@"
preonepost pretwopost prethreepost
Notes
- The
#
matches the beginning - The
%
matches the end - Using double quotes around
${@}
considers each element as a separate word. so replacement happens for every positional parameter
I would use shell [ parameter expansion ] for this
$ set -- one two three
$ echo "$@"
one two three
$ set -- "${@/#/pre}" && set -- "${@/%/post}"
$ echo "$@"
preonepost pretwopost prethreepost
Notes
- The
#
matches the beginning - The
%
matches the end - Using double quotes around
${@}
considers each element as a separate word. so replacement happens for every positional parameter
edited Nov 2 '18 at 10:29
Community♦
11
11
answered Jul 25 '16 at 2:09
sjsamsjsam
15.9k33170
15.9k33170
2
This is nice and compact. The OP should consider making this the accepted solution.
– John1024
Jul 25 '16 at 2:54
add a comment |
2
This is nice and compact. The OP should consider making this the accepted solution.
– John1024
Jul 25 '16 at 2:54
2
2
This is nice and compact. The OP should consider making this the accepted solution.
– John1024
Jul 25 '16 at 2:54
This is nice and compact. The OP should consider making this the accepted solution.
– John1024
Jul 25 '16 at 2:54
add a comment |
Let's create a parameters for test purposes:
$ set -- one two three
$ echo "$@"
one two three
Now, let's use bash to add prefixes and suffixes:
$ IFS=$'n' a=($(printf "pre/%s/postn" "$@"))
$ set -- "${a[@]}"
$ echo -- "$@"
pre/one/post pre/two/post pre/three/post
Limitations: (a) since this uses newline-separated strings, it won't work if your $@
contains newlines itself. In that case, there may be another choice for IFS
that would suffice. (b) This is subject to globbing. If either of these is an issue, see the more general solution below.
On the other hand, if the positional parameters do not contain whitespace, then no change to IFS
is needed.
Also, if IFS
is changed, then one may want to save IFS
beforehand and restore afterward.
More general solution
If we don't want to make any assumptions about whitespace, we can modify "$@" with a loop:
$ a=(); for p in "$@"; do a+=("pre/$p/post"); done
$ set -- "${a[@]}"
$ echo "$@"
pre/one/post pre/two/post pre/three/post
Why do we need to change IFS here? I tried without it seems to work
– Richard
Jul 25 '16 at 1:23
What it the magic behind this set?
– Richard
Jul 25 '16 at 1:26
4
@Richard It is only important to change IFS if you have spaces or tabs in your parameters. Otherwise, it is not needed.set
is a shell builtin that, among other things, sets the positional parameters.
– John1024
Jul 25 '16 at 1:35
1
@John1024:a=( $(echo '*') ); declare -p a
. The output from the command substitution is subject to globbing.
– mklement0
Jul 25 '16 at 2:16
1
@mklement0 OK. Thanks. I updated the answer to note that that issue applies to the first approach.
– John1024
Jul 25 '16 at 2:22
|
show 2 more comments
Let's create a parameters for test purposes:
$ set -- one two three
$ echo "$@"
one two three
Now, let's use bash to add prefixes and suffixes:
$ IFS=$'n' a=($(printf "pre/%s/postn" "$@"))
$ set -- "${a[@]}"
$ echo -- "$@"
pre/one/post pre/two/post pre/three/post
Limitations: (a) since this uses newline-separated strings, it won't work if your $@
contains newlines itself. In that case, there may be another choice for IFS
that would suffice. (b) This is subject to globbing. If either of these is an issue, see the more general solution below.
On the other hand, if the positional parameters do not contain whitespace, then no change to IFS
is needed.
Also, if IFS
is changed, then one may want to save IFS
beforehand and restore afterward.
More general solution
If we don't want to make any assumptions about whitespace, we can modify "$@" with a loop:
$ a=(); for p in "$@"; do a+=("pre/$p/post"); done
$ set -- "${a[@]}"
$ echo "$@"
pre/one/post pre/two/post pre/three/post
Why do we need to change IFS here? I tried without it seems to work
– Richard
Jul 25 '16 at 1:23
What it the magic behind this set?
– Richard
Jul 25 '16 at 1:26
4
@Richard It is only important to change IFS if you have spaces or tabs in your parameters. Otherwise, it is not needed.set
is a shell builtin that, among other things, sets the positional parameters.
– John1024
Jul 25 '16 at 1:35
1
@John1024:a=( $(echo '*') ); declare -p a
. The output from the command substitution is subject to globbing.
– mklement0
Jul 25 '16 at 2:16
1
@mklement0 OK. Thanks. I updated the answer to note that that issue applies to the first approach.
– John1024
Jul 25 '16 at 2:22
|
show 2 more comments
Let's create a parameters for test purposes:
$ set -- one two three
$ echo "$@"
one two three
Now, let's use bash to add prefixes and suffixes:
$ IFS=$'n' a=($(printf "pre/%s/postn" "$@"))
$ set -- "${a[@]}"
$ echo -- "$@"
pre/one/post pre/two/post pre/three/post
Limitations: (a) since this uses newline-separated strings, it won't work if your $@
contains newlines itself. In that case, there may be another choice for IFS
that would suffice. (b) This is subject to globbing. If either of these is an issue, see the more general solution below.
On the other hand, if the positional parameters do not contain whitespace, then no change to IFS
is needed.
Also, if IFS
is changed, then one may want to save IFS
beforehand and restore afterward.
More general solution
If we don't want to make any assumptions about whitespace, we can modify "$@" with a loop:
$ a=(); for p in "$@"; do a+=("pre/$p/post"); done
$ set -- "${a[@]}"
$ echo "$@"
pre/one/post pre/two/post pre/three/post
Let's create a parameters for test purposes:
$ set -- one two three
$ echo "$@"
one two three
Now, let's use bash to add prefixes and suffixes:
$ IFS=$'n' a=($(printf "pre/%s/postn" "$@"))
$ set -- "${a[@]}"
$ echo -- "$@"
pre/one/post pre/two/post pre/three/post
Limitations: (a) since this uses newline-separated strings, it won't work if your $@
contains newlines itself. In that case, there may be another choice for IFS
that would suffice. (b) This is subject to globbing. If either of these is an issue, see the more general solution below.
On the other hand, if the positional parameters do not contain whitespace, then no change to IFS
is needed.
Also, if IFS
is changed, then one may want to save IFS
beforehand and restore afterward.
More general solution
If we don't want to make any assumptions about whitespace, we can modify "$@" with a loop:
$ a=(); for p in "$@"; do a+=("pre/$p/post"); done
$ set -- "${a[@]}"
$ echo "$@"
pre/one/post pre/two/post pre/three/post
edited Dec 10 '17 at 19:35
answered Jul 25 '16 at 1:15
John1024John1024
74.9k86694
74.9k86694
Why do we need to change IFS here? I tried without it seems to work
– Richard
Jul 25 '16 at 1:23
What it the magic behind this set?
– Richard
Jul 25 '16 at 1:26
4
@Richard It is only important to change IFS if you have spaces or tabs in your parameters. Otherwise, it is not needed.set
is a shell builtin that, among other things, sets the positional parameters.
– John1024
Jul 25 '16 at 1:35
1
@John1024:a=( $(echo '*') ); declare -p a
. The output from the command substitution is subject to globbing.
– mklement0
Jul 25 '16 at 2:16
1
@mklement0 OK. Thanks. I updated the answer to note that that issue applies to the first approach.
– John1024
Jul 25 '16 at 2:22
|
show 2 more comments
Why do we need to change IFS here? I tried without it seems to work
– Richard
Jul 25 '16 at 1:23
What it the magic behind this set?
– Richard
Jul 25 '16 at 1:26
4
@Richard It is only important to change IFS if you have spaces or tabs in your parameters. Otherwise, it is not needed.set
is a shell builtin that, among other things, sets the positional parameters.
– John1024
Jul 25 '16 at 1:35
1
@John1024:a=( $(echo '*') ); declare -p a
. The output from the command substitution is subject to globbing.
– mklement0
Jul 25 '16 at 2:16
1
@mklement0 OK. Thanks. I updated the answer to note that that issue applies to the first approach.
– John1024
Jul 25 '16 at 2:22
Why do we need to change IFS here? I tried without it seems to work
– Richard
Jul 25 '16 at 1:23
Why do we need to change IFS here? I tried without it seems to work
– Richard
Jul 25 '16 at 1:23
What it the magic behind this set?
– Richard
Jul 25 '16 at 1:26
What it the magic behind this set?
– Richard
Jul 25 '16 at 1:26
4
4
@Richard It is only important to change IFS if you have spaces or tabs in your parameters. Otherwise, it is not needed.
set
is a shell builtin that, among other things, sets the positional parameters.– John1024
Jul 25 '16 at 1:35
@Richard It is only important to change IFS if you have spaces or tabs in your parameters. Otherwise, it is not needed.
set
is a shell builtin that, among other things, sets the positional parameters.– John1024
Jul 25 '16 at 1:35
1
1
@John1024:
a=( $(echo '*') ); declare -p a
. The output from the command substitution is subject to globbing.– mklement0
Jul 25 '16 at 2:16
@John1024:
a=( $(echo '*') ); declare -p a
. The output from the command substitution is subject to globbing.– mklement0
Jul 25 '16 at 2:16
1
1
@mklement0 OK. Thanks. I updated the answer to note that that issue applies to the first approach.
– John1024
Jul 25 '16 at 2:22
@mklement0 OK. Thanks. I updated the answer to note that that issue applies to the first approach.
– John1024
Jul 25 '16 at 2:22
|
show 2 more comments
Note: This is essentially a slightly more detailed version of sjam's answer.
John1024's answer is helpful, but:
- requires a subshell (which involves a child process)
- can result in unwanted globbing applied to the array elements.
Fortunately, Bash parameter expansion can be applied to arrays too, which avoids these issues:
set -- 'one' 'two' # sample input array, which will be reflected in $@
# Copy $@ to new array ${a[@]}, adding a prefix to each element.
# `/#` replaces the string that follows, up to the next `/`,
# at the *start* of each element.
# In the absence of a string, the replacement string following
# the second `/` is unconditionally placed *before* each element.
a=( "${@/#/PREFIX}" )
# Add a suffix to each element of the resulting array ${a[@]}.
# `/%` replaces the string that follows, up to the next `/`,
# at the *end* of each element.
# In the absence of a string, the replacement string following
# the second `/` is unconditionally placed *after* each element.
a=( "${a[@]/%/SUFFIX}" )
# Print the resulting array.
declare -p a
This yields:
declare -a a='([0]="PREFIXoneSUFFIX" [1]="PREFIXtwoSUFFIX")'
Note that double-quoting the array references is crucial to protect their elements from potential word-splitting and globbing (filename expansion) - both of which are instances of shell expansions.
add a comment |
Note: This is essentially a slightly more detailed version of sjam's answer.
John1024's answer is helpful, but:
- requires a subshell (which involves a child process)
- can result in unwanted globbing applied to the array elements.
Fortunately, Bash parameter expansion can be applied to arrays too, which avoids these issues:
set -- 'one' 'two' # sample input array, which will be reflected in $@
# Copy $@ to new array ${a[@]}, adding a prefix to each element.
# `/#` replaces the string that follows, up to the next `/`,
# at the *start* of each element.
# In the absence of a string, the replacement string following
# the second `/` is unconditionally placed *before* each element.
a=( "${@/#/PREFIX}" )
# Add a suffix to each element of the resulting array ${a[@]}.
# `/%` replaces the string that follows, up to the next `/`,
# at the *end* of each element.
# In the absence of a string, the replacement string following
# the second `/` is unconditionally placed *after* each element.
a=( "${a[@]/%/SUFFIX}" )
# Print the resulting array.
declare -p a
This yields:
declare -a a='([0]="PREFIXoneSUFFIX" [1]="PREFIXtwoSUFFIX")'
Note that double-quoting the array references is crucial to protect their elements from potential word-splitting and globbing (filename expansion) - both of which are instances of shell expansions.
add a comment |
Note: This is essentially a slightly more detailed version of sjam's answer.
John1024's answer is helpful, but:
- requires a subshell (which involves a child process)
- can result in unwanted globbing applied to the array elements.
Fortunately, Bash parameter expansion can be applied to arrays too, which avoids these issues:
set -- 'one' 'two' # sample input array, which will be reflected in $@
# Copy $@ to new array ${a[@]}, adding a prefix to each element.
# `/#` replaces the string that follows, up to the next `/`,
# at the *start* of each element.
# In the absence of a string, the replacement string following
# the second `/` is unconditionally placed *before* each element.
a=( "${@/#/PREFIX}" )
# Add a suffix to each element of the resulting array ${a[@]}.
# `/%` replaces the string that follows, up to the next `/`,
# at the *end* of each element.
# In the absence of a string, the replacement string following
# the second `/` is unconditionally placed *after* each element.
a=( "${a[@]/%/SUFFIX}" )
# Print the resulting array.
declare -p a
This yields:
declare -a a='([0]="PREFIXoneSUFFIX" [1]="PREFIXtwoSUFFIX")'
Note that double-quoting the array references is crucial to protect their elements from potential word-splitting and globbing (filename expansion) - both of which are instances of shell expansions.
Note: This is essentially a slightly more detailed version of sjam's answer.
John1024's answer is helpful, but:
- requires a subshell (which involves a child process)
- can result in unwanted globbing applied to the array elements.
Fortunately, Bash parameter expansion can be applied to arrays too, which avoids these issues:
set -- 'one' 'two' # sample input array, which will be reflected in $@
# Copy $@ to new array ${a[@]}, adding a prefix to each element.
# `/#` replaces the string that follows, up to the next `/`,
# at the *start* of each element.
# In the absence of a string, the replacement string following
# the second `/` is unconditionally placed *before* each element.
a=( "${@/#/PREFIX}" )
# Add a suffix to each element of the resulting array ${a[@]}.
# `/%` replaces the string that follows, up to the next `/`,
# at the *end* of each element.
# In the absence of a string, the replacement string following
# the second `/` is unconditionally placed *after* each element.
a=( "${a[@]/%/SUFFIX}" )
# Print the resulting array.
declare -p a
This yields:
declare -a a='([0]="PREFIXoneSUFFIX" [1]="PREFIXtwoSUFFIX")'
Note that double-quoting the array references is crucial to protect their elements from potential word-splitting and globbing (filename expansion) - both of which are instances of shell expansions.
edited May 23 '17 at 12:14
Community♦
11
11
answered Jul 25 '16 at 1:59
mklement0mklement0
127k20241269
127k20241269
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2fstackoverflow.com%2fquestions%2f38558401%2fadd-prefix-and-suffix-to-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
You will have to iterate over array and add prefix and suffix to each entry.
– Sameer Naik
Jul 25 '16 at 1:10
Are you looking to add a prefix an suffix to every argument, or add new prefix and suffix arguments on either side of the set of existing arguments? E.g. if your prefix is
P
and your suffix isS
and$@
is1 2 3
are you looking forP1S P2S P3S
orP 1 2 3 S
?– dimo414
Jul 25 '16 at 1:42
1
I'm looking for
P1S P2S P3S
– Richard
Jul 25 '16 at 1:44