Bash - variables in quotes

I am trying to make a bash function to automatically add everything that has not been verified or changed in my working tree, commit it and click.

It looks like this:

gcp() {
    git add -- .;
    git commit -m \"$1\";
    git push origin $2;
}

However, when I check this, I get:

$ gcp "test this" master
error: pathspec 'this"' did not match any file(s) known to git.

How to get the correct citation behavior around variables?

+4
source share
1 answer

You should not avoid quotes. I also propose quoting all the arguments. Maybe your branch has a place in it, who knows? And you only need semicolons if you add more statements on one line.

gcp() {
    git add -- .
    git commit -m "$1"
    git push origin "$2"
}
+6
source

Source: https://habr.com/ru/post/1598620/


All Articles