📜 ⬆️ ⬇️

Programming on the phone using the Termux terminal emulator

Greetings to the readers! In this article I will talk about how you can write programs with android phone. I say right away - root rights are not needed.

What do we need?


The first thing we need is an android phone with the Termux application installed on it (available on Google Play ). To complete the work with the terminal, we need enough memory. With dozens of installed packages, the application takes up 1.5 GB of memory.
Also, for comfortable coding, it is desirable that the phone be with OTG support, and you have a USB-connected keyboard to write code on the keyboard (where it is more convenient). If we don’t have this, then download the keyboard Hacker's Keyboard . It has the Ctrl key, which is important to us.


')

Why Termux?


Termux has enough packages in its arsenal for working with programming languages: C / C ++, Python, Golang, PHP, Lua.
There are also databases, I only know about mariadb and postgresql.

Start


image
Each time you start the application, we see a greeting, which shows the main commands for working with the terminal:


For coding, we need a text editor. There are different options, I chose Vim and briefly tell you how to work with it.
Install vim:
$ pkg install vim 

For an example of working with vim, write “Hello World” in C.
 $ vim main.c 

After that, Vim starts. To start writing code, you need to press the "i" key.
Write the code:
 #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } 

After that, press the "Esc" key, put a colon and write wq (": wq"). This will save our file and changes to it (w - write) and close it (q - quit).

It is important to know!

w - save changes to file
wa - save changes to all files
q - close file
qa - close all files
wq - save changes and close the file

Now we need to compile this code. First, install the compiler:
 $ pkg install gcc 

Further we write the following:
 $ gcc -Wall main.c -o program 

main.c - file with our code
program - our program.

Now we can run our program and see if it works:
 $ ./program 

or
 $ sh program 

Result:
 Hello World! 


the end


This was an introductory article on phone programming. Please write in the comments if you need to continue: working with databases, code examples and running them on other PL, working with the terminal itself, and so on.

Source: https://habr.com/ru/post/343760/


All Articles