Why does linux recognise a C# .cs file as a C++ source file?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I used the file command on a c# source file, and linux thought it was a c++ file. What is the reason for this?







share|improve this question

























    up vote
    2
    down vote

    favorite












    I used the file command on a c# source file, and linux thought it was a c++ file. What is the reason for this?







    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I used the file command on a c# source file, and linux thought it was a c++ file. What is the reason for this?







      share|improve this question













      I used the file command on a c# source file, and linux thought it was a c++ file. What is the reason for this?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 7 at 2:52









      muru

      33.2k576140




      33.2k576140









      asked Jun 7 at 2:34









      J. Czekaj

      132




      132




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          Take a look at the man page for the file command:




          $ man file



          ...



          file tests each argument in an attempt to classify it.
          There are three sets of tests, performed in this order: filesystem
          tests
          , magic tests, and language tests. The first test that succeeds
          causes the file type to be printed.




          It's the third test (language tests) that file performs that's categorizing this file as a C++ file.




          Once file has determined the character set used in a text-type file,
          it will attempt to determine in what language the file is written.
          The language tests look for particular strings (cf. #include
          ) that can appear anywhere in the first few blocks of a file. For example, the keyword .br indicates that the file is most likely a
          troff(1) input file, just as the keyword struct indicates a C program.
          These tests are less reliable than the previous two groups, so they are performed last. The language test routines also test for some
          miscellany (such as tar(1) archives).




          C# files most closely match to C++ files and so file "guesses" that the .cs file is a C++ file.



          Example



          $ more blah.cs
          // A Hello World! program in C#.
          using System;
          namespace HelloWorld

          class Hello

          static void Main()

          Console.WriteLine("Hello World!");

          // Keep the console window open in debug mode.
          Console.WriteLine("Press any key to exit.");
          Console.ReadKey();





          Checking with file:



          $ file blah.cs
          blah.cs: ASCII C++ program text





          share|improve this answer





















          • Add to this: the original file command looks only at file contents, not the filename. So it doesn’t recognize that a .cs file contains syntax that looks vaguely like C++ but which is actually a different language C#. // Many folks extend file to look at the filename as well, but that produces other problems.
            – Krazy Glew
            Jun 7 at 4:23










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f448319%2fwhy-does-linux-recognise-a-c-cs-file-as-a-c-source-file%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          Take a look at the man page for the file command:




          $ man file



          ...



          file tests each argument in an attempt to classify it.
          There are three sets of tests, performed in this order: filesystem
          tests
          , magic tests, and language tests. The first test that succeeds
          causes the file type to be printed.




          It's the third test (language tests) that file performs that's categorizing this file as a C++ file.




          Once file has determined the character set used in a text-type file,
          it will attempt to determine in what language the file is written.
          The language tests look for particular strings (cf. #include
          ) that can appear anywhere in the first few blocks of a file. For example, the keyword .br indicates that the file is most likely a
          troff(1) input file, just as the keyword struct indicates a C program.
          These tests are less reliable than the previous two groups, so they are performed last. The language test routines also test for some
          miscellany (such as tar(1) archives).




          C# files most closely match to C++ files and so file "guesses" that the .cs file is a C++ file.



          Example



          $ more blah.cs
          // A Hello World! program in C#.
          using System;
          namespace HelloWorld

          class Hello

          static void Main()

          Console.WriteLine("Hello World!");

          // Keep the console window open in debug mode.
          Console.WriteLine("Press any key to exit.");
          Console.ReadKey();





          Checking with file:



          $ file blah.cs
          blah.cs: ASCII C++ program text





          share|improve this answer





















          • Add to this: the original file command looks only at file contents, not the filename. So it doesn’t recognize that a .cs file contains syntax that looks vaguely like C++ but which is actually a different language C#. // Many folks extend file to look at the filename as well, but that produces other problems.
            – Krazy Glew
            Jun 7 at 4:23














          up vote
          2
          down vote



          accepted










          Take a look at the man page for the file command:




          $ man file



          ...



          file tests each argument in an attempt to classify it.
          There are three sets of tests, performed in this order: filesystem
          tests
          , magic tests, and language tests. The first test that succeeds
          causes the file type to be printed.




          It's the third test (language tests) that file performs that's categorizing this file as a C++ file.




          Once file has determined the character set used in a text-type file,
          it will attempt to determine in what language the file is written.
          The language tests look for particular strings (cf. #include
          ) that can appear anywhere in the first few blocks of a file. For example, the keyword .br indicates that the file is most likely a
          troff(1) input file, just as the keyword struct indicates a C program.
          These tests are less reliable than the previous two groups, so they are performed last. The language test routines also test for some
          miscellany (such as tar(1) archives).




          C# files most closely match to C++ files and so file "guesses" that the .cs file is a C++ file.



          Example



          $ more blah.cs
          // A Hello World! program in C#.
          using System;
          namespace HelloWorld

          class Hello

          static void Main()

          Console.WriteLine("Hello World!");

          // Keep the console window open in debug mode.
          Console.WriteLine("Press any key to exit.");
          Console.ReadKey();





          Checking with file:



          $ file blah.cs
          blah.cs: ASCII C++ program text





          share|improve this answer





















          • Add to this: the original file command looks only at file contents, not the filename. So it doesn’t recognize that a .cs file contains syntax that looks vaguely like C++ but which is actually a different language C#. // Many folks extend file to look at the filename as well, but that produces other problems.
            – Krazy Glew
            Jun 7 at 4:23












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          Take a look at the man page for the file command:




          $ man file



          ...



          file tests each argument in an attempt to classify it.
          There are three sets of tests, performed in this order: filesystem
          tests
          , magic tests, and language tests. The first test that succeeds
          causes the file type to be printed.




          It's the third test (language tests) that file performs that's categorizing this file as a C++ file.




          Once file has determined the character set used in a text-type file,
          it will attempt to determine in what language the file is written.
          The language tests look for particular strings (cf. #include
          ) that can appear anywhere in the first few blocks of a file. For example, the keyword .br indicates that the file is most likely a
          troff(1) input file, just as the keyword struct indicates a C program.
          These tests are less reliable than the previous two groups, so they are performed last. The language test routines also test for some
          miscellany (such as tar(1) archives).




          C# files most closely match to C++ files and so file "guesses" that the .cs file is a C++ file.



          Example



          $ more blah.cs
          // A Hello World! program in C#.
          using System;
          namespace HelloWorld

          class Hello

          static void Main()

          Console.WriteLine("Hello World!");

          // Keep the console window open in debug mode.
          Console.WriteLine("Press any key to exit.");
          Console.ReadKey();





          Checking with file:



          $ file blah.cs
          blah.cs: ASCII C++ program text





          share|improve this answer













          Take a look at the man page for the file command:




          $ man file



          ...



          file tests each argument in an attempt to classify it.
          There are three sets of tests, performed in this order: filesystem
          tests
          , magic tests, and language tests. The first test that succeeds
          causes the file type to be printed.




          It's the third test (language tests) that file performs that's categorizing this file as a C++ file.




          Once file has determined the character set used in a text-type file,
          it will attempt to determine in what language the file is written.
          The language tests look for particular strings (cf. #include
          ) that can appear anywhere in the first few blocks of a file. For example, the keyword .br indicates that the file is most likely a
          troff(1) input file, just as the keyword struct indicates a C program.
          These tests are less reliable than the previous two groups, so they are performed last. The language test routines also test for some
          miscellany (such as tar(1) archives).




          C# files most closely match to C++ files and so file "guesses" that the .cs file is a C++ file.



          Example



          $ more blah.cs
          // A Hello World! program in C#.
          using System;
          namespace HelloWorld

          class Hello

          static void Main()

          Console.WriteLine("Hello World!");

          // Keep the console window open in debug mode.
          Console.WriteLine("Press any key to exit.");
          Console.ReadKey();





          Checking with file:



          $ file blah.cs
          blah.cs: ASCII C++ program text






          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jun 7 at 3:01









          slm♦

          234k65480653




          234k65480653











          • Add to this: the original file command looks only at file contents, not the filename. So it doesn’t recognize that a .cs file contains syntax that looks vaguely like C++ but which is actually a different language C#. // Many folks extend file to look at the filename as well, but that produces other problems.
            – Krazy Glew
            Jun 7 at 4:23
















          • Add to this: the original file command looks only at file contents, not the filename. So it doesn’t recognize that a .cs file contains syntax that looks vaguely like C++ but which is actually a different language C#. // Many folks extend file to look at the filename as well, but that produces other problems.
            – Krazy Glew
            Jun 7 at 4:23















          Add to this: the original file command looks only at file contents, not the filename. So it doesn’t recognize that a .cs file contains syntax that looks vaguely like C++ but which is actually a different language C#. // Many folks extend file to look at the filename as well, but that produces other problems.
          – Krazy Glew
          Jun 7 at 4:23




          Add to this: the original file command looks only at file contents, not the filename. So it doesn’t recognize that a .cs file contains syntax that looks vaguely like C++ but which is actually a different language C#. // Many folks extend file to look at the filename as well, but that produces other problems.
          – Krazy Glew
          Jun 7 at 4:23












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f448319%2fwhy-does-linux-recognise-a-c-cs-file-as-a-c-source-file%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay