Why am I intermittently getting "syntax error near unexpected token `('" from my function definition, depending upon the terminal I use?

95 views Asked by At

I suspect that I have an issue similar to Alias causes error: syntax error near unexpected token `(', (exact same error message) yet it differs in that:

  1. I am trying to define a function, not an alias.
  2. I have other functions defined in the exact same way as far as I can tell, that work fine.
  3. The error disappears if I use a different terminal emulator (iTerm2 to be specific).

The tl;dr section of the linked question's top voted answer states:

You need to quote your alias command not just for its definition, but also for its use as-is on the resulting command line.

The simplest solution in your case is to use a combination of outer '...' quoting with inner "..." quoting (other solutions exist; note that the use of "..." for inner quoting means that if your definition contained variable references, they'd [be] expanded when the alias is used)

But this makes zero sense to me. Bash is seemingly picking up a ` character where there is none, either in the OP's situation or in mine.

The appropriate section of my .bash_aliases file:

# Checkout the given branch of mine, without having to type the "users/kent/" prefix
gc() { git checkout users/kent/$1; }

# Create and checkout a new branch in my user folder, without having to type the "users/kent/" prefix
gcb() { git checkout -b users/kent/$1; }

# Rename a local Git branch, without having to type the "users/kent/" prefix
gr() { git branch -m users/kent/$1; }

Within the integrated terminal in JetBrains Rider (a cross-platform .NET IDE), the top two aliases work fine, but the bottom one doesn't...which is extremely confusing to me, especially since they all work in iTerm2!

0

There are 0 answers