A quick look at COBOL on Linux

Confession: I got through a 41 year career in IT, mostly in banking and government, without ever compiling or running a COBOL program. I recently saw A very short introduction to COBOL, which describes how to install COBOL on a Mac and how to compile and run a very simple COBOL program. So I tried this on Ubuntu Linux 20.04.

Install gnu-cobol.

I did this with Synaptic, my preferred tool for such tasks. One small glitch is that I could not find gnu-cobol. However, Ubuntu has gnucobol (no hyphen) and I went with that.

Once this is done, you’ll have access to the cobc command.
This is the man page for it:
man cobc

This worked and I got the same output as in the article.

I created a hello.cob file and opened it in VS Code. Immediately a popup told me some extensions could help with .cob files. I’m impressed.

This worked for me. Yes, Microsoft does have Visual Studio Code for Linux. In fact, I am using it right now. I also installed the COBOL extension mentioned, which is now at v7.0.14. The syntax highlighting looks good.

I copied the code into hello.cob and compiled it with cobc -x hello.cob. The first time I got

hello.cob: 6: warning: line not terminated by a newline

So I added a carriage return at the end of the last line and it compiled cleanly. It ran as specified, giving the traditional “Hello, World!” message. A nice simple tutorial.

1 thought on “A quick look at COBOL on Linux

  1. Pingback: The Lifetime of Programming Languages | From Hilbert Space to Dilbert Space, and beyond

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.