I'm writing a shell script that needs to perform certain operations based on the last commit's message of my local branches with a name starting with task. Here's what my script looks like #!/bin/bashgit branch | while read branch_name;    do         if [[ $branch_name == task* ]];         then             git log --format=%s -n 1 ${branch_name}        fi    doneWhen i run this script I get the following output : fatal: ambiguous argument 'task/foo':  unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git  [...] -- [...]'Which is weird because I have a branch named task/foo (and also because the name is directly read from the output of git branch). I tried adding -- at the end of the git log, as suggested but then I get the following error : fatal: bad revision 'task/foo'When I do the exact same command inside a shell, everything works fine : $ git log --format=%s -n 1 task/foo  Initial commit (Readme, license)EditAs suggested, I tried placing my variable between double quotes, like below, but I still have the same result. #!/bin/bashgit branch | while read branch_name;    do         if [[ $branch_name == task* ]];         then             git log --format=%s -n 1 ${branch_name}        fi    doneI also tried the script suggested by Klaatu, but this also give me the same error. Edit 2Here's the output when I add set -x to my script : + git branch+ read branch_name+ [[ * develop == task* ]]+ read branch_name+ [[ master == task* ]]+ read branch_name+ [[ task/foo == task* ]]+ git log --format=%s -n 1 'task/foo'fatal: ambiguous argument 'task/foo': unknown revision or path not in the working tree.Use '--' to separate paths from revisions, like this:'git <command> [<revision>...] -- [<file>...]'+ read branch_nameUse '--' to separate paths from revisions, like this:'git  [...] -- [...]'+ read branch_name
Git unknown revision error when within bash script
shell;shell script;git