Find out extension of executable files?

When I am building software from source on a GNU+Linux system, during the ./configure stage I frequently see the following line:

checking for suffix of executables...

How do I create such a check in a bash script?

The reason I want to know this is that I want to create a makefile in which it compiles with suffix .exe on Cygwin, but no suffix on true GNU+Linux.

This will give you the extension of the file:

echo "${FILENAME##*.}"


Answered By: captcha

The test is done by compiling a small dummy C program and by checking how the compiler names the output file.

The following example is a simplified version of what configure is doing


cat << EOT > dummy.c
int main(int argc, char ** argv) {
    return 0;

gcc -o dummy dummy.c

if [ -f dummy.exe ] ; then
  # exe

I would suggest you to use autoconf to generate a configure script and use it for your purpose.

Answered By: Matteo