Sponsored Content
Operating Systems Linux Android Enhancing the very limited Command Line. Post 302931978 by wisecracker on Saturday 17th of January 2015 04:20:57 PM
Old 01-17-2015
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...
 

6 More Discussions You Might Find Interesting

1. Solaris

limited ping "command" at solaris

Hi... Iam new members at this forum. and I have a little problem with "command ping" what the "command to ping at limited time", for example at linux $ping -c5 10.0.0.62 and the responed as below: 64 bytes from 10.0.0.62: icmp_seq=1 ttl=128 time=0.843 ms 64 bytes from 10.0.0.62: icmp_seq=2... (3 Replies)
Discussion started by: srilinux
3 Replies

2. Shell Programming and Scripting

Enhancing Script (using loops) to go through for each group

Currently I have written a shell script that will add departments for one group (displayed below with configuration file). I want to enhance the script in order to add departments to multiple groups by: 1. Making changes to allow the script to loop through and write each dept/group combo into... (0 Replies)
Discussion started by: dolo21taf
0 Replies

3. Red Hat

Enhancing security of temporary folder

While enhancing security of my temporary folder in the post described in Secure temporary folders on existing Unix or Linux systems | SysAdmin.MD my redirection fails. This commands always fails echo "/mnt/tmp /tmp ext3 loop,noexec,nosuid,rw 0 0" >> /etc/fstab Can anybody please tell my why? (1 Reply)
Discussion started by: synthea
1 Replies

4. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

6. Shell Programming and Scripting

Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line?

I am looking for help in processing of those options: '-n' or '-p' I understand what they do and how to use them. But, I would like to use them with more than one file (and without any shell-loop; loading the 'perl' once.) I did try it and -n works on 2 files. Question is: - is it possible to... (6 Replies)
Discussion started by: alex_5161
6 Replies
dos2unix(1)						      General Commands Manual						       dos2unix(1)

NAME
dos2unix - DOS/MAC to UNIX text file format converter SYNOPSYS
dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...] Options: [-hkqV] [--help] [--keepdate] [--quiet] [--version] DESCRIPTION
This manual page documents dos2unix, the program that converts plain text files in DOS/MAC format to UNIX format. OPTIONS
The following options are available: -h --help Print online help. -k --keepdate Keep the date stamp of output file same as input file. -q --quiet Quiet mode. Suppress all warning and messages. -V --version Prints version information. -c --convmode convmode Sets conversion mode. Simulates dos2unix under SunOS. -o --oldfile file ... Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used. -n --newfile infile outfile ... New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or you WILL lost your files. EXAMPLES
Get input from stdin and write output to stdout. dos2unix Convert and replace a.txt. Convert and replace b.txt. dos2unix a.txt b.txt dos2unix -o a.txt b.txt Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. Convert c.txt from Mac to Unix ascii format. dos2unix a.txt -c iso b.txt dos2unix -c ascii a.txt -c iso b.txt dos2unix -c mac a.txt b.txt Convert and replace a.txt while keeping original date stamp. dos2unix -k a.txt dos2unix -k -o a.txt Convert a.txt and write to e.txt. dos2unix -n a.txt e.txt Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt. dos2unix -k -n a.txt e.txt Convert and replace a.txt. Convert b.txt and write to e.txt. dos2unix a.txt -n b.txt e.txt dos2unix -o a.txt -n b.txt e.txt Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt. dos2unix -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt DIAGNOSTICS
BUGS
The program does not work properly under MSDOS in stdio processing mode. If you know why is that so, please tell me. AUTHORS
Benjamin Lin - <blin@socs.uts.edu.au> Bernd Johannes Wuebben (mac2unix mode) <wuebben@kde.org> MISCELLANY
Tested environment: Linux 1.2.0 with GNU C 2.5.8 SunOS 4.1.3 with GNU C 2.6.3 MS-DOS 6.20 with Borland C++ 4.02 Suggestions and bug reports are welcome. SEE ALSO
unix2dos(1) mac2unix(1) 1995.03.31 dos2unix v3.0 dos2unix(1)
All times are GMT -4. The time now is 08:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy