0

set -x "g++" "/usr/local/gcc-7.1/bin/g++-7.1"

will not work due to non-alphanumeric "++" characters. (Error message: "set: Invalid character “+” in variable name.")

Am I out of luck here or is there a work around? I just switched to fish less than 24 hours ago and not sure if there is a work around for aliasing g++.

Thanks for your time.

2 Answers2

1

The simplest:

alias g++ /usr/local/gcc-7.1/bin/g++-7.1
ridiculous_fish
  • 17,273
  • 1
  • 54
  • 61
  • My question was imprecise. I should not have used "alias" - I am trying to avoid aliases in my setup (I have 100+ of them in Bash) and aliases are (reportedly) slow in fish shell as well. But @ridiculous_fish had the answer: I created an alias for g++ interactively, executed "type g++" and saved the output as a function. –  Nov 29 '17 at 14:06
  • No need to go via `type` - fish has `funcsave`, so `funcsave g++`. – faho Nov 29 '17 at 15:42
0

set doesn't create an alias, it sets a variable.

So set -x g++ something is trying to set a variable called "g++" to the value "something" and export it (the "-x").

Now, you most likely want to do what ridiculous_fish suggested and define an actual alias (or a function - which alias desugars to, or an abbreviation) with alias or function or abbr.

Also, the "+" character isn't allowed in variable names. That's because, while fish could allow it, other shells don't. And since variables can be exported, their names need to be compatible with those (try g++=something in bash - it'll try to run it as a command). See Allowed characters in linux environment variable names for further information.

faho
  • 14,470
  • 2
  • 37
  • 47