0

I've defined a bunch of zsh aliases for compiling my projects, which will basically cd into my projects directory, and compile the relevant project (which I pass as an argument). Now, I want to include which branch I am building to the output of the function, but am having some difficulty in how to express that in zsh.

I tried using the following below to grab the branch, but to no avail.

function buildproject {
    echo "Building project ~/$1 $(git -C '/Users/myuser/$1' branch | grep \* | cut -d ' ' -f2)";

Instead, I get

fatal: cannot change to '/Users/myuser/$1': No such file or directory

And looking at my syntax highlighting, it doesn't seem to recognize the parameter. How can I get zsh to use the parameter?

Jeeter
  • 5,887
  • 6
  • 44
  • 67
  • Use double quotes instead of single quotes around any string in which you want expansion to occur. – Charles Duffy Aug 06 '19 at 21:56
  • (I closed this with a bash duplicate, but the specifically relevant subset of semantics are identical). – Charles Duffy Aug 06 '19 at 21:57
  • @CharlesDuffy Oh, interesting. I thought that the double quotes would have interfered with the echo. I guess since they're inside the $() it's different? – Jeeter Aug 06 '19 at 21:58
  • BTW, `grep '[*]'` is going to be a lot more reliable. Some versions will treat a single `*` as invalid regex syntax (which it is), rather than as a literal string to match. – Charles Duffy Aug 06 '19 at 21:58
  • 1
    Right, `$( ... )` opens a new quoting context. – Charles Duffy Aug 06 '19 at 21:58
  • 1
    (That's one of the things that makes `$( ... )` better than backticks; the way backticks interact with quotes, backslashes, and other syntax is... complicated). – Charles Duffy Aug 06 '19 at 22:02
  • Cool, thanks! Didn't realize that was the issue haha – Jeeter Aug 06 '19 at 22:03

0 Answers0