You can find out your own phone number on your Android handset by looking at Settings -> Device Info -> Status. Doing it programmatically, though, is not a trivial task, but the following method works if your handset is rooted.
On my Samsung Galaxy S5 SCL23 (the Japanese carrier Au’s version), the following script works (with the root privilege invoked). The presence of a Busybox binary is assumed because applets ‘awk’ and ‘tr’ are used.
#service call iphonesubinfo 8 | awk -F\' '{print $2}' | tr -d '.\n'
This is based on “How to get the phone number of an android phone via adb? – Stack Overflow.” According to this article, the number “8” above depends on your Android version. The article then references “Public scratchpad: Calling Android services from ADB shell” for a way to automatically figure it out from a *nix box—but I did not go that far.
I wanted to execute this script from Automate—a Tasker-like automation app for Android from Llamalab (Automate on Google Play). Special care had to be taken about the literal text string for this command because in Automate, curly braces are special characters and used to signify in-place text substitution (“interpolation”) in literal text strings, so left curly braces have to be quoted if otherwise (see pic).
Before executing this script in a Shell command Superuser block, I have it converted by the ‘cliEncode’ function just to be on the safe side (see pic).