Share This
//Expanding the Scope of Shell Capabilities through Theory and Application

Expanding the Scope of Shell Capabilities through Theory and Application

    ★ Can it be used as expected? Bash on Ubuntu on Windows.

Since 8/2016, [Bash on Ubuntu on Windows] (hereafter referred to as BoW) has been integrated into Windows 10, allowing us to use both Ubuntu and Bash on Windows.
Many people might think that [it would be interesting to develop like this]?
We have used BoW to simulate a real development environment to verify whether it meets expectations.

Using BoW to Develop an Application

Introduced in the Windows 10 Anniversary Update, [Bash on Ubuntu on Windows] was enhanced by the Creators Update in April 2017, with development tools also ready for use. In this article, we will verify whether using BoW for development is truly as expected.

Environment
We carry out development and verify the issues in this chapter using the following environment.
Windows 10 Pro 64bit, version 1703, build 15063.138 (Creators Update)
16GB RAM
Intel Core i7-5500U CPU @ 2.40GHz

BoW uses the following after the Creators Update [Reference 1].
▼Reference 1 Bash on Ubuntu on Windows information used in this article (*1)
$ uname -a
Linux DESKTOP-T3CMM04 4.4.0-43-Microsoft #1-Microsoft ⇙
Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"

(*1) Regarding terminal display, specifically when no log is present, the terminal for BoW will be displayed, not the Command prompt.

The method of integrating BoW is omitted in this article. Please refer to the integration method via an article on the internet (*2).
Once integrated, you can launch from the Start Menu by selecting [Bash on Ubuntu on Windows] or by pressing key …+ …, then entering bash in the dialog that appears to specify the file name to execute.

(*2) Reference Link

Verification Content

To verify, we will develop a simple sample application as follows and confirm the experience when using it.(*3)
(*3) Sample Code is available on GitHub.

●Developing a Web application with Java and Play Framework
●Developing Front-End using Vue.js and npm
●Developing a simple Twitter Client with Python

Additionally, we have also verified tasks such as creating a COBOL environment for Mastodon to run.
Examples like this are introduced on the author’s blog, so feel free to take a look if interested (*4).
(*4) Link 1 Link 2

BoW and Windows Environment Connectivity
In practice, when using BoW, developers will likely use Editors or IDEs on Windows. Since it is not possible to reference BoW’s shared folders from Windows, we will create a folder (C:¥work), which will be referenced by both BoW and Windows for development. It is better to create a symbolic link in $HOME for easier usage as shown in [Reference 2].

▼Reference 2 Creating a symbolic link to a folder for tasking on Windows
$ ln -s /mnt/c/work $HOME/work
$ ln -l work
lrwxrwxrwx 1 kunst kunst 11 April 29 17:58 work -> /mnt/c/work

Install Open JDK 8 using apt on BoW environment.
$ sudo apt-get install openjdk-8-jdk

Sbt is installed following [Reference 3] of [Install sbt for Linux] on the official site (*7).

▼Reference 3 Installing sbt
$ echo "deb https://dl.bintray.com/sbt/debian /" | ⇙
sudo tee -a /etc/apt/sources.list.d/sbt.list
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 ⇙
--recv 2EE0E64E40A89B84B2DF73499E82A75642AC823
$ sudo apt-get update
$ sudo apt-get install sbt

(*7) Reference Link

Preparing for Development (BoW)

In the BoW environment, create a template for a Play Application. When creating the template, use the sbt new command (*8).

(*8) Reference Link
$ sbt new playframework/play-java-seed.g8
There will be several questions posed during the setup, but according to [Reference 4], leaving most fields blank and pressing Enter is fine.

▼Reference 4 Questions when creating a template
This template generates a Play Java project
name [play-java-seed]: play-java8-sample ←Enter project name
organization [com.example]: ←Leave blank then Enter
scala_version [2.11.11]: ←Leave blank then Enter
play_version [2.5.14]: ←Leave blank then Enter

Template applied in ./play-java8-sample

Preparing for Development (Windows)

Since we can create a template for a project using BoW, we can open the created project (C:¥work¥play-java8-sample) from Windows.
In the IDE, we use IntelliJ IDEA (when compiling Java applications on Windows, JDK is also required in this environment).

DEVELOP
We started the dev server using BoW and edited the source code with Windows IDE to proceed with the development.
Start the dev server with the following command:
$ npm run dev

Then, access [localhost:8080] from the browser. Since hot deploy and hot reload are configured, the screen will automatically reload whenever the source code changes. (As shown in Figure 11)
Development starts with this setup.

Since the sample code is mostly similar to what has been introduced on the page mentioned in Note 10, we will omit further explanation here.
Since BoW can use npm, we can develop without installing npm on Windows.
The author ran npm on BoW and overwrote it successfully.

Utilities: open command
The Creators Update in April 2017 allowed binary execution directly on Windows from BoW.
It opens the current directory and executes commands like the Mac’s open command, which is very convenient.

Create the script in List 3 for [$HOME/bin/open], and set the PATH for [$HOME/bin] in .bashrc.
Now you can open directories like `open` and `open word\js-sample`.
However, note that with BoW’s architecture, you cannot open directories outside of the Windows folders (e.g., directories within /mnt/c/).

List 3 bin/open
#! /bin/bash
"if [ $# -eq 0 ]; then
DIR=.
else
DIR=""$*""
fi
explorer.exe $DIR"

Utility [Path modification command]
Using the terminal on BoW, GUI on Windows is often desirable for or not wanting to use Windows’ Path in BoW.
In such cases, creating a command like List 1 or List 2 will be more convenient.
For example, below:
$ echo "/mnt/c/work/python-sample" | u2w
C:\work\python-sample
$ echo "C:\work\python-sample|e" | w2u
/mnt/c/work/python-sample

▼ List 1 Command to change Path from Windows to Ubuntu Path (bin/w2u)
#!/bin/bash
sed 's_ \\_/_g' | sed -r 's_^(.)(:)_/mnt/\L\1_g'

▼ List 2 Command to change Path from Ubuntu to Windows
#!/bin/bash
sed -r 's_^(/mnt/)(.)_\U\2:_g' | 's_/_\\_g'

Developing a Twitter Client Easily with Python

Next, we proceed with using Python to develop a Twitter client.
Since this is only for verifying the development environment, we will just create a simple CLI client to display a timeline.

Preparing for Development (BoW)
Since the standard package management tool for BoW isn’t installed, we proceed to install it.
$ sudo apt install python3-pip

Use pip to install the necessary libraries.
$ pip3 install requests_oauthlib

Preparing for Development (Windows)
For verifying Python development, we don’t use project samples.
Create a directory [C://work/python-sample] on Windows, open it in a text editor like Atom.

Develop
Additionally, this time we won’t use a dev server.
We will use the Windows editor to edit the source, and immediately execute it from BoW.
The complete code is available on GitHub note 13.

So we run the tool using the command line.
It will display the timeline as shown in Map 12.

As a simple verification, calling the Twitter API from Python in BoW, we can perform tasks such as data extraction.

Conclusion

The verification conducted on various languages like Java, JavaScript, Python, across all environments shows that as long as we are prepared, development can proceed normally (though it might require some setup).
From a personal use perspective, it feels like creating a Linux virtual machine in a Windows environment for development.
When developing on Windows, a lot of development tools must be installed, which could lead to environment chaos. However, using BoW as a development environment, we can clearly separate environments to have advantages like automating shell scripts.
Furthermore, it can be run in its native environment, not just on virtual machines. Therefore, in the future, it could be a viable choice for development.

Reconfiguring BoW Environment
The author will introduce the steps for reconfiguring the BoW environment if it doesn’t run as expected or when restructuring it from scratch.
Open Command Prompt as administrator and run these two commands:
> lxrun /uninstall
> lxrun /install

Even if restructured, the directories /root and /home are not deleted, so settings like users, .bashrc files can be reused as before.

Map 12 Twitter client after completion:
$ ./sample.py
おやすみなさい
...

How to Use Python Integrated in BoW with Visual Studio Code

For Python development, the IDE was initially planned to use Visual Studio Code. However, integrating Python directly in BoW with Visual Studio Code was difficult, and this article skips the usage. Of course, if it can be installed in the Windows environment, it can be used normally.
However, for testing purposes, Python can be used in BoW from Visual Studio Code. Additionally, Pylint (Python code checker) cannot be used in this method.
First, we install a Python plugin as shown in Figure 13. After installation, restart Visual Studio Code and you will see Python files highlighted.
Then, press Ctrl + , to open the settings.json file and modify it (as in List 4). Then edit the “C:\work\python.bat” file in settings.json, adding the content in List 5.
After setting it up, right-click in the Visual Studio Code editor, select “Run Python File in Terminal” and the file will run on the IDE (as shown in Figure 14).
In any case, I think BoW will be best supported in Visual Studio Code (hopefully), so I want to switch to it.

Figure 13: Install the plugin for Python

List 4: Modify settings.json
// To overwrite the default settings, declare them inside this file
{
"python.pythonPath": "C:/work/python.bat"
}

List 5: python.bat
bash.exe -c "echo %* | sed 's_\\\\_/_g' | sed -r 's_^(.)(:)_/mnt/\\L\\1_g' | xargs python3"

Figure 14: Run Python in BoW from Visual Studio Code


APPLY NOW






    Benefits

    SALARY & BONUS POLICY

    RiverCrane Vietnam sympathizes staffs' innermost feelings and desires and set up termly salary review policy. Performance evaluation is conducted in June and December and salary change is conducted in January and July every year. Besides, outstanding staffs receive bonus for their achievements periodically (monthly, yearly).

    TRAINING IN JAPAN

    In order to broaden staffs' view about technologies over the world, RiverCrane Vietnam set up policy to send staffs to Japan for study. Moreover, the engineers can develop their career paths in technical or management fields.

    ANNUAL COMPANY TRIP

    Not only bringing chances to the staffs for their challenging, Rivercrane Vietnam also excites them with interesting annual trips. Exciting Gala Dinner with team building games will make the members of Rivercrane connected closer.

    COMPANY'S EVENTS

    Activities such as Team Building, Company Building, Family Building, Summer Holiday, Mid-Autum Festival, etc. will be the moments worthy of remembrance for each individual in the project or the pride when one introduces the company to his or her family, and shares the message "We are One".

    INSURANCE

    Rivercrane Vietnam ensures social insurance, medical insurance and unemployment insurance for staffs. The company commits to support staffs for any procedures regarding these insurances. In addition, other insurance policies are taken into consideration and under review.

    OTHER BENEFITS

    Support budget for activities related to education, entertainment and sports. Support fee for purchasing technical books. Support fee for getting engineering or language certificates. Support fee for joining courses regarding technical management. Other supports following company's policy, etc.

    © 2012 RiverCrane Vietnam. All rights reserved.

    Close