Bash Programming Cheat
Sheet

Written By: ph34r

A quick cheat sheet for programmers who want to do shell
scripting. This is not intended to teach programming, etc. but
it is intended for a someone who knows one programming language
to begin learning about bash scripting.

Basics

All bash scripts must tell the o/s what to use as the
interpreter. The first line of any script should be:

#!/bin/bash

You must make bash scripts executable.

chmod +x filename

Variables

Create a variable – just assign value. Variables are
non-datatyped (a variable can hold strings, numbers, etc. with
out being defined as such).

varname=value

Access a variable by putting $ on the front of the name

echo $varname

Values passed in from the command line as arguments are
accessed as $# where #= the index of the variable in the array
of values being passed in. This array is base 1 not base 0.

command var1 var2 var3 …. varX

$1 contains whatever var1 was, $2 contains whatever var2 was,
etc.

Built in variables:

$1-$N Stores the arguments (variables) that were passed to
the shell program from the command line.
$? Stores the exit value of the last command that was
executed.
$0 Stores the first word of the entered command (the
name of the shell program).
$* Stores all the arguments that were entered on the
command line ($1 $2 …).
“$@” Stores all the arguments that were entered on the
command line, individually quoted (“$1″ “$2″ …).

Quote Marks

Regular double quotes (“like these”) make the shell ignore
whitespace and count it all as one argument being passed or
string to use. Special characters inside are still
noticed/obeyed.

Single quotes ‘like this’ make the interpreting shell ignore
all special characters in whatever string is being passed.

The back single quote marks (`command`) perform a different
function. They are used when you want to use the results of a
command in another command. For example, if you wanted to set
the value of the variable contents equal to the list of files
in the current directory, you would type the following command:
contents=`ls`, the results of the ls program are put in the
variable contents.

Logic and comparisons

A command called test is used to evaluate conditional
expressions, such as a if-then statement that checks the
entrance/exit criteria for a loop.

test expression

Or

[ expression ]

Numeric Comparisons

int1 -eq int2 Returns True if int1 is equal to int2.
int1 -ge int2 Returns True if int1 is greater than or equal to
int2.
int1 -gt int2 Returns True if int1 is greater than int2.
int1 -le int2 Returns True if int1 is less than or equal to
int2
int1 -lt int2 Returns True if int1 is less than int2
int1 -ne int2 Returns True if int1 is not equal to int2

String Comparisons

str1 = str2 Returns True if str1 is identical to str2.
str1 != str2 Returns True if str1 is not identical to str2.
str Returns True if str is not null.
-n str Returns True if the length of str is greater than
zero.
-z str Returns True if the length of str is equal to zero.
(zero is different than null)

File Comparisons

-d filename Returns True if file, filename is a directory.
-f filename Returns True if file, filename is an ordinary
file.
-r filename Returns True if file, filename can be read by the
process.
-s filename Returns True if file, filename has a nonzero
length.
-w filename Returns True if file, filename can be written by the
process.
-x filename Returns True if file, filename is executable.

Expression Comparisons

!expression

Returns true if expression is not true

expr1 -a expr2

Returns True if expr1 and expr2 are true. ( && , and
)

expr1 -o expr2

Returns True if expr1 or expr2 is true. ( ||, or )

Logic Con’t.

If…then

if [ expression ]

then

commands

fi

If..then…else

if [ expression ]

then

commands

else

commands

fi

If..then…else If…else

if [ expression ]

then

commands

elif [ expression2 ]

then

commands

else

commands

fi

Case select

case string1 in

str1)

commands;;

str2)

commands;;

*)

commands;;

esac

string1 is compared to str1 and str2. If one of these strings
matches string1, the commands up until the double semicolon (;
;) are executed. If neither str1 nor str2 matches string1, the
commands associated with the asterisk are executed. This is the
default case condition because the asterisk matches all
strings.

Iteration (Loops)

for var1 in list

do

commands

done

This executes once for each item in the list. This list can be
a variable that contains several words separated by spaces
(such as output from ls or cat), or it can be a list of values
that is typed directly into the statement. Each time through
the loop, the variable var1 is assigned the current item in the
list, until the last one is reached.

while [ expression ]

do

commands

done

until [ expression ]

do

commands

done

Functions

Create a function:

fname(){

commands

}

Call it by using the following syntax: fname

Or, create a function that accepts arguments:

fname2 (arg1,arg2…argN){

commands

}

And call it with: fname2 arg1 arg2 … argN

Orignal Location  :http://linux-sxs.org/programming/bashcheat.html

Issues when porting or developing an application for ARM Embedded Linux
”Get as much better performance, with the smallest memory footprint”
Similar to any platform for the code to be portable it should

  • Program according to standards
  • Use intrinsics

and should not

Neon Architecture

December 27, 2009

What is NEON

ARM NEON technology is a 128 bit SIMD (Single Instruction, Multiple Data)
architecture extension for the ARM CortexTM-A series processors, designed to provide flexible and powerful acceleration for intensive multimedia applications, thereby delivering a significantly enhanced user experience.

Some of the benefits…

  • Aligned and unaligned data access allows for efficient vectorization of SIMD operations.
  • Support for both integer and floating point operations
  • Tight coupling to the ARM core provides a single instruction stream and a unified view of memory, presenting a single development platform target with a simpler tool flow.
  • The large NEON register file with its multiple views enables efficient handling of data and minimizes access to memory, enhancing data throughput performance.

Reference:

Portability and Optimizations of GNU Applications for ARM Embedded Linuxhttp://tree.celinuxforum.org/CelfPubWiki/ELCEurope2008Presentations?action=AttachFile&do=get&target=ARM_EmbeddedLinux_Apps_Port.pdf

VNC tools

August 18, 2009

VNC packages +ves
UltraVNC easy movement of files, looks better than tightVNC but not as good as RealVNC
TightVNC easy movement of files + works with mac natively
RealVNC faster and better looking , more polished vivek’s Vote

Of Course all of these do most of the major stuff

http://www.realvnc.com/cgi-bin/download.cgi

Norms and Crest Factor

An n – norm is defined as

The most common norm is &

= rms value

and

= max( |u(t)| )

The creast factor of a non-zero signal is defined as the ratio of peak to rms value

CF(u) = 1

A CF of 1 indicates a signal which only stays at

Therefore a signal with a low crest factor spends most of the time near the peek values.

A creast factor of 1 implies a square wave of amplitude

In terms of amplitude distribution –

, where is the total length of set E

the proportion of the time a where |u(t)| > a

= min{a|=0}

and

Which is a weighted integral of the amplitude distribution or if we plot a graph of vs a, is the

todo: update the crest factor definition in Wiki http://en.wikipedia.org/wiki/Normed_vector_space

Crest factor of a multi-tone Signal

For a following multitone signal with N tones

We have mean, = , regardless of phase

The goal is to minimize the crest factor

Andrioid Notes

August 18, 2009

Application framework built over Linux kernel

+ Libraries
+ Android runtime
- Dalbik VM (JAva VM improved – memory optimized etc.)
+ Applications
- Primarily in Java ->

Eclipse Based Development with Android Plugin for ARM platforms

Applications
+ No Main entry Point
+ Provides
- Activity (has UI)
- Services ( no UI)
- Broadcast reciver (broadcast message)
- Content Provider (makes data aviable to other application)
+ AndroidManifest.xml – define program

android presentation from mentor graphics

  • Auto-correlation Algorithm

http://cnx.org/content/m11714/latest/

measure energy and zero crossing.

  • Voiced Signals : high energy – low frequency (low zero crossing)
  • Unvoiced Signals : low energy – high frequency (big zero crossing)
  • Noise : Low energy + low frequency (overall low zero crossing)

Vowels :

Consonants :

formants : Peak of frequency spectrum

LPC
Another method, which is used to obtain a frequency spectrum is that of Linear Predictive Coding(LPC). This is the most successful method in widespread use today. The idea behind LPC is that the values of the signal can be expressed as a linear combination of the preceding values. That is, if s(i) is the amplitude at time i,
s(i) = a1*s(i-1) + a2*s(i-2) + … + ap*s(i-p)
When the input data is filled in, this becomes a system of linear equations which can be solved to determine the values of a1 through ap. These values then produce a very noise free signal, which clearly identifies the formants. Typical values for p are 10-12.

http://www.cs.dartmouth.edu/~dwagn/aiproj/speech.html

Logarithms on floats

July 22, 2008

Logarithms are usually computed by using a an iterative algorithm like taylor series or another iterative algorithm.

Easy Solution: Floating point representation of a number separates the number into an exponent, a sign and a mantissa. The number represented is then N=M*2^E.

The log of that number would be LOG(N)=LOG(M * 2^E)=LOG(M) + E*LOG(2). If we assume M is normalized, 1<=M<2, then 0 <=LOG(M) <=LOG(2). The LOG of the exponent gives us the coarse estimate of the LOG (to 6dB), which can be found by just multiplying the exponent by a constant (LOG(2) in the appropriate base). (A constant offset may need to be added to the exponent e.g. for IEEE representation we need to compensate for offset of 128 in offset)

For Finer precision obtain an estimate of the log of mantissa and add that to the logarithm of the exponent. The logarithm of the mantissa can be found using a small look-up table addressed by the most significant bits of M. By only using 32 entry long table (5 bits) an accuracy of around 0.25 dB can be obtained.

Other Log for floating point notes from the web

MPEG-4

July 10, 2008

Follow

Get every new post delivered to your Inbox.