Unix/Linux Go Back    


Android Brand new forum for folks interesting in Linux and Java-based Android OS and multi-platform mobile computing in general.

Enhancing the very limited Command Line.

Android


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-17-2015
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 29 March 2017, 5:32 AM EDT
Location: Loughborough
Posts: 1,176
Thanks: 353
Thanked 312 Times in 242 Posts
Enhancing the very limited Command Line.

Sometime ago, somewhere on here, I said I was going to do some coding for Android.
I installed the full dev kit and a few months ago this MBP developed a failed HDD consequently destroying the dev environment.

I got an Android phone for XMAS and downloaded a terminal program.

I then found out how VERY limited the command line was/is.
I have no intention of rooting the phone at the moment as I want to see what I can create with the limited access available...
I also do not intend downloading a text editor - see the end of this upload...

Many things we take for granted are not available and there is very limited I/O;
printf, tr, sed, od, xxd, hexdump and many many other commands are not available.
This has set me on a quest to create some tools, albeit some might be slow, to aid is shell scripting.
(A basic DEMO hex dumper using echo is elsewhere on here but here are some more simpler other ones.)

1) ENVARC - Who remembers that then eh! <wink>
This is called as . ./ENVARC and adds the TMPDIR variable that does not exist in Android and extends the PATH to include another /some/path/to/Home/bin folder for executables.

Code:
#!/system/bin/sh
# ENVARC
PATH=$PATH:/storage/sdcard0/Home/bin
TMPDIR=/storage/sdcard0/Home/tmp

This can be called/sourced from the command line or inside any code you write...

2) reset - A terminal reset command that seems to reset the terminal and DOES clear the screen.

Code:
#!/system/bin/sh
# reset<CR>
echo -n -e "\x1Bc\x1B[0m\x1B[2J\x1B[H"
clear

3) d2u - A dos2unix workalike.

Code:
#!/system/bin/sh
# d2u <infile> [outfile]<CR>
. /storage/sdcard0/Home/bin/ENVARC
ifs_str="$IFS"
IFS=""
newfile=""
substring=0
outfile=$2
if [ "$1" == "" ]
then
	echo "Usage: d2u <infile> [outfile]..."
	exit 1
fi
if [ "$2" == "" ]
then
	outfile=$1
fi
read -s -d '' -r oldfile < $1
while [ $substring -lt ${#oldfile} ]
do
	if [ "${oldfile:$substring:1}" == $'\r' ]
	then
		substring=$((substring+1))
	else
		newfile=$newfile${oldfile:$substring:1} 
		substring=$((substring+1))
	fi
done
IFS="$ifs_str"
echo -n "$newfile" > $outfile
echo "File, $1, now converted to UNIX format..."
exit 0

And finally my editor running inside my new */bin folder, ( yes I do have Ctrl-C <wink>), cat > my_executable with Ctrl-C to exit...

A cleaned up version of the hex dumper is next then I am going to attempt a simple text editor as there are no editors either...

If there are better coding practices then I am completely open to them.

Bazza...
Sponsored Links
    #2  
Old Unix and Linux 01-18-2015
drl's Unix or Linux Image
drl drl is offline Forum Advisor  
Registered Voter
 
Join Date: Apr 2007
Last Activity: 29 March 2017, 7:12 PM EDT
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,076
Thanks: 186
Thanked 364 Times in 317 Posts
Hi.

Off the top of my head:

Code:
shtool (1)           - The GNU Portable Shell Tool
busybox (1)          - The Swiss Army Knife of Embedded Linux

Best wishes ... cheers, drl
The Following User Says Thank You to drl For This Useful Post:
M3ntalPurg3 (02-07-2016)
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Enhancing security of temporary folder synthea Red Hat 1 08-09-2009 04:52 AM
Enhancing Script (using loops) to go through for each group dolo21taf Shell Programming and Scripting 0 04-30-2008 11:12 PM



All times are GMT -4. The time now is 12:45 AM.