August 1, 2016

Howdy, Ubuntu on Windows! Write and Execute Your First Program

linux-on-windows-dustin-kirkland-firefly.jpg

Ubuntu on Windows
Canonical developer Dustin Kirkland is a space cowboy on the great Ubuntu-on-Windows frontier.

Microsoft’s addition of the Bash shell and Ubuntu user space in Windows 10 is a real win for developers working in dynamic, interpreted programming languages everywhere. Dozens of dynamic script interpreters are now immediately available on Windows desktops.

In this article, we’re going to write the classic “hello world” application in several different dynamically executed languages, install any necessary dependencies, and execute our interpreted code.

If you’d like to follow along this article and try out these examples, you can grab all of the source code from Git:

$ sudo apt update

$ sudo apt install -y git

$ git clone https://github.com/dustinkirkland/howdy-windows.git

$ cd howdy-windows

 

Now, let’s look at each language:

  1. Bash

  • Installation

    • None, bash is always installed in the default image, but just in case...

    • sudo apt install -y bash

  • Code: bash/howdy.sh

#!/bin/sh

echo "    ====> Shell: Howdy, Windows!”

  • Compilation

    • None, bash is an interpreted language

  • Execution

        $ chmod +x ./bash/howdy.sh

$ ./bash/howdy.sh

   ====> Shell: Howdy, Windows!

  1. Python

  • Installation

    • None, python is always installed in the default image, but just in case…

$ sudo apt install -y python

  • Code: python/howdy.py

        #!/usr/bin/python

print("    ====> Python: Howdy, Windows!")

  • Compilation

    • None, python is an interpreted language

  • Execution

        $ chmod +x ./python/howdy.py

$ ./python/howdy.py

   ====> Python: Howdy, Windows!

  1. Perl

  • Installation

$ sudo apt install -y perl

  • Code: perl/howdy.pl

        #!/usr/bin/perl

print("    ====> Perl: Howdy, Windows!\n");

  • Compilation

    • None, Perl is an interpreted language

  • Execution

        $ chmod +x ./perl/howdy.pl

$ ./perl/howdy.pl

   ====> Perl: Howdy, Windows!

  1. Ruby

  • Installation

$ sudo apt install -y ruby

  • Code: ruby/howdy.rb

        #!/usr/bin/ruby

puts "    ====> Ruby: Howdy, Windows!"

  • Compilation

    • None, Ruby is an interpreted language

  • Execution

        $ chmod +x ./ruby/howdy.rb

$ ./ruby/howdy.rb

   ====> Ruby: Howdy, Windows!

  1. PHP

  • Installation

$ sudo apt install -y php5-cli

  • Code: php/howdy.php

        #!/usr/bin/php

<?php

 print("    ===> PHP: Howdy, Windows!\n")

?>

  • Compilation

    • None, PHP is an interpreted language

  • Execution

        $ chmod +x ./php/howdy.php

$ ./php/howdy.php

   ===> PHP: Howdy, Windows!

  1. Node.js

  • Installation

$ sudo apt install -y nodejs

  • Code: nodejs/howdy.js

        console.log('    ====> NodeJS: Howdy, Windows!');

  • Compilation

    • None, Node.js is an interpreted language

  • Execution

        $ nodejs nodejs//howdy.js

   ====> NodeJS: Howdy, Windows!

 

Cheers,

Dustin

Read the next article in the series: Howdy, Ubuntu on Windows! Writing for Compiled Languages

Read previous articles in the series:

Howdy, Ubuntu on Windows! An Intro From Canonical's Dustin Kirkland

Howdy, Ubuntu on Windows! Getting Started

Howdy, Ubuntu on Windows! Ubuntu Commands Every Windows User Should Learn

Learn more about Running Linux Workloads on Microsoft Azure in this on-demand webinar with guest speaker Ian Philpot of Microsoft. Watch Now >>