My team share a shell script, I want to make it Cygwin-compatible because only me is on Windows. Now the problem comes from source. My shell only accepts format like:

source ./<file name>

instead of

source <file name>

which is already in the script. So I want to override source like:

source(){ . ./$@; }

But now my shell complains that:

`source': is a special builtin

What should I do for now?

  • 3
    Are you sure it's not just because of a mismatch in the $PATH? source uses the $PATH if the filename isn't explicit. Does your $PATH include .? Non-explicit paths are dangerous anyway, so I would tell your developers to fix the scripts. Apr 6 '17 at 13:58
  • @EightBitTony at least with Bash on Linux, it tries $PWD after $PATH, even though there is no . in my $PATH.
    – derobert
    Apr 6 '17 at 14:40
  • Uh, no. $PWD is in fact not automagically fake-added to $PATH by default. Why would you presume this to be so?
    – DopeGhoti
    Apr 6 '17 at 15:15
  • @DopeGhoti was that directed at me? If so, I'd presume it be so because I tested it, and the bash manpage documents the behavior as well. In fact, I just tested it on a fresh Cygwin install, where it is too.
    – derobert
    Apr 6 '17 at 15:29
  • @Elderry I tried on a fresh Cygwin install, and it works for me. Is your Cygwin using a non-bash shell, or maybe your bash is set to run in POSIX mode?
    – derobert
    Apr 6 '17 at 15:30

From that error message about a special builtin (see http://sources.debian.net/src/bash/4.4-4/execute_cmd.c/?hl=5623#L5623), it appears you're running bash in POSIX mode. This might be because you have $POSIXLY_CORRECT set, ran the shell with --posix, used set -o posix, etc.

One of the many things POSIX mode does (in addition to not let you override source) is make source (and .) not search the current working directory if $PATH-lookup fails.

This has nothing to do with running on Cygwin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.