0

The question is probably hard to understand so it's probably better with an illustrative example.

echo "function testcmd() { alias echo-test='echo test'; } " > define_testcmd; source defin
e_testcmd && testcmd && echo-test

throws a error echo-test: command not found.

Calling echo-test after this line works.

  • You can't. Use a function instead – oguz ismail Feb 02 '23 at 07:28
  • I concur; don't use aliases. Perhaps tangentially see also https://stackoverflow.com/questions/57239089/why-would-i-create-an-alias-which-creates-a-function though it is basically about the opposite case. – tripleee Feb 02 '23 at 08:00
  • You can't use an alias on the same line where it's defined; see Dennis Williamson's answer [here](https://stackoverflow.com/questions/2501056/cant-get-expand-aliases-to-take-effect/2502451#2502451). Basically, aliases are kluges, with lots of weird limitations and sharp edges. Use functions instead. – Gordon Davisson Feb 02 '23 at 08:21

0 Answers0