When you place [double quotes][1] around an [expansion][2], such as the [parameter expansion][3] `$*`, the expanded text is not subject to [word splitting][4]. (That's one of the reasons to use double quotes around `$` expansions; the other is to prevent [globbing][5].) Furthermore, inside double quotes, [single quotes][6] are not treated specially, so they do not perform quoting and they are not [removed][7].
So, as [Michael Homer says][8], you can just **omit the spurious `'` `'` marks** and your function should work. I suggest writing it like this:
<!-- language: lang-bash -->
gac() {
git add .
git commit -m "$*"
}
You can use the `function` keyword to define functions in Bash but the syntax shown above works just as well and is portable across Bourne-style shells.
---
To address the conceptual issue here more directly, this line in your original code shows that you wanted to expand a parameter whose value contained spaces, in such a way that you could pass it as a single argument to `git`:
<!-- language: lang-bash -->
concatenated="'$*'"
When you write a single argument yourself that contains spaces, you quote the spaces, usually with quotes around the whole string. The presence of `'` `'` *inside* the `"` `"` in that line tells me that you were trying to include the quotes that you would normally type.
The reason that approach does not work is that **the shell itself is what interprets your quotes; they don't typically mean anything to the command you run from the shell**. Suppose you have the command:
some-command 'foo bar' baz
That command does not actually pass any quotation marks to the `some-command` command. Instead, it runs `some-command` with `foo bar` as [argument][9] 1 and `baz` as argument 2. (There is also an argument 0, which tells a program how it was run; the shell passes `some-command` for that.)
Using quotes enables you to *tell the shell* where arguments begin and end. Spaces normally tell the shell to treat the text on each side as separate arguments<sup>**1**</sup>, but you want to suppress the spaces' special meaning to the shell, which is what quoting does. When quotes are quoted, like the inner `'` `'` inside `"` `"`, that removes *their* special meaning too. Then they don't perform quoting, but are instead passed literally to your command, as `git` showed in its log:
a382806 'one two three'
---
<sup>**1**</sup> [In the operation of the shell][10], spaces and tabs divide text into separate words in two related but distinct ways. First, [when a command is initially parsed][11], unquoted spaces and tabs separate lexical tokens. Other [metacharacters][12] do this, too, but they have additional effects--for example, `;` divides a line into multiple commands. Second, where [parameter expansion][3] or any other [shell expansion][2] signified by a `$`<sup>**2**</sup> is performed in an unquoted context, the result is immediately subjected to [word splitting][4], which [uses the characters in `$IFS` as delimiters][13]. The [default value of `IFS`][14] is a space followed by a tab followed by a newline.
<sup>**2**</sup> Or [command substitution][15], even if the `` ` `` `` ` `` syntax is used instead of the `$(` `)` syntax.
[1]: https://www.gnu.org/software/bash/manual/bash.html#Double-Quotes
[2]: https://www.gnu.org/software/bash/manual/bash.html#Shell-Expansions
[3]: https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion
[4]: https://www.gnu.org/software/bash/manual/bash.html#Word-Splitting
[5]: https://www.gnu.org/software/bash/manual/bash.html#Filename-Expansion
[6]: https://www.gnu.org/software/bash/manual/bash.html#Single-Quotes
[7]: https://www.gnu.org/software/bash/manual/bash.html#Quote-Removal
[8]: https://unix.stackexchange.com/questions/399774/passing-string-containing-spaces-as-command-line-argument-from-within-script#comment713953_399774
[9]: https://en.wikipedia.org/wiki/Command-line_interface#Arguments
[10]: https://www.gnu.org/software/bash/manual/bash.html#Shell-Operation
[11]: https://www.gnu.org/software/bash/manual/bash.html#Shell-Syntax
[12]: https://www.gnu.org/software/bash/manual/bash.html#index-metacharacter
[13]: https://www.gnu.org/software/bash/manual/bash.html#index-IFS
[14]: https://unix.stackexchange.com/a/120578/11938
[15]: https://www.gnu.org/software/bash/manual/bash.html#Command-Substitution