Bash: syntax error: unexpected end of file

When you get:

syntax error: unexpected end of file

You should make sure that you don't have problems with end of line characters, however the ERROR in logic of your code (bad command) wil cause that as well.

Sometimes it is easier to comment out all lines with "# your code"and turn on some little-by-little.


As an Amazon Associate I earn from qualifying purchases.

Unix: dos2unix on Mac

Removing Windows line ends on Mac:

In Terminal.app

$ cat file1.txt | col -b > file2.txt

Warning: Do not run this with destination of the same file, or it will become empty.



As an Amazon Associate I earn from qualifying purchases.

Android: re-installing a bunch of apps with one script

I have a bunch (over a dozen) of APKs that go together on the device as a single solution, to remove them and reinstall all of them would be a time consuming effort, so I have scripts for that.

Do not believe "-r" option in "adb install -r", it does not always re-install the app.

I have a single script with bunch of uninstalls...

adb uninstall com.xyz.x1
$ adb uninstall com.xyz.x2
...
$ cd your_apks
# install all APKs in this folder
$ for i in *.apk; do adb install -r $i; done


As an Amazon Associate I earn from qualifying purchases.

UNIX: -bash: xyz.bash: cannot execute binary file

You create your script file but it does not want to execute...

Terminal.app error:

 -bash: xyz.bash: cannot execute binary file


Step 1:

Make sure it has execute permissions

@ scripts $ chmod 777 xyz.bash 

Step 2:

Make sure scrip does not have ERROR inside, special characters that prevent execution.


As an Amazon Associate I earn from qualifying purchases.

Starting with Go language by Google

http://golang.org/

1. Download and Install the Go - no configuration needed
2. Add variable:
~@ ~ $ edit ~/.profile


# Go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin

3. Close and open Terminal

@ ~ $ which go
/usr/local/go/bin/go

4. create a sample program

@ workspaces $ mkdir go_programs
@ workspaces $ touch hello.go
@ workspaces $ edit hello.go 
@ workspaces $

Editor:

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}


Edit PATH again:

# Go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=~/Documents/workspaces/go_programs
export PATH=$PATH:$GOPATH


5. Run your first program
@ workspaces $  go run hello.go
hello, world

6. Take a tour
http://tour.golang.org/#1



As an Amazon Associate I earn from qualifying purchases.

Chicago Events & SF Bay Area Events apps updated!

     "Chicago Events" and "SF Bay Area Events" apps get an update! We have the best coverage in of events (conferences, meetups), with multiple category calendars, twitter handles and other goodies.. Download if you want to follow what is going on in Chicago or San Francisco Bay Area.

We have improved: 

- event synchronization, 
- better menu selection 
- and event filtering.

Download our apps here.



The app also gets a great re-sizable WIDGET for your Android desktop



As an Amazon Associate I earn from qualifying purchases.

Terminal: set command line prompt and PATH variables in Bash ~/.profile

As a developer you will find yourself using Command Line (Terminal.app) every day, all the time, so it is worthwhile to set it up to behave just right for you...

Open Application > Utilities > Terminal.app (drag it to your toolbar for quick access)

My shell looks like that, it tells me a lot of info just as verification...

Last login: Mon Sep 15 11:56:15 on ttys000
edit ~/.profile
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b05)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b05, mixed mode)
git version 1.9.0
/Applications/Android/SDK/android-sdk-macosx/platform-tools/adb
uki@ CNH_PROD $ vi ~/.profile


We can use vi editor, but on daily basis I just type "edit ~/.profile"

# ANDROID - updated: Sept 15, 2014
export ANDROID_HOME=/Applications/Android/SDK/android-sdk-macosx
export PATH=${PATH}:${ANDROID_HOME}/build-tools/19.0.3
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
export PATH=${PATH}:${ANDROID_HOME}/tools

echo "edit ~/.profile"
# Adjust prompt.
# \d – Current date
# \t – Current time
# \h – Host name
# \# – Command number
# \u – User name
# \W – Current working directory (ie: Desktop/)
# \w – Current working directory, full path (ie: /Users/Admin/Desktop)
export PS1="\u@ \W $ "
java -version
git version
which adb


To EDIT hit "i" for insert
To Save and Quit you type ESC + :wq + Enter
I have MUCH MORE configurations in there, but it is specific to what you have on your computer.


As an Amazon Associate I earn from qualifying purchases.

Getting Info About APK

Often you have apk that you need (e.g. package, version) info for, but you have no documentation about it. This little command gives you a lot of info.

$ aapt dump badging  someapp.apk
package: name='com.someapp.xyz' versionCode='1' versionName='1.1'
sdkVersion:'15'
targetSdkVersion:'17'
application-label:'SomeApp'
application: label='SomeApp' icon=''
application-debuggable
uses-feature:'android.hardware.touchscreen'
uses-implied-feature:'android.hardware.touchscreen','assumed you require a touch screen unless explicitly made optional'
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--'
densities: '160' '240' '320'
uki:~ uki$


As an Amazon Associate I earn from qualifying purchases.

Android: updating SDK from command line

You may want to create a script "Update Android SDK.bash" that quickly gets you up to speed without starting IDE (e.g. Eclipse) UI.

echo 'Android SDK home ' $ANDROID_HOME
$ANDROID_HOME/tools/android update sdk --no-ui --all --force 



Notice that it will ask you several times to click letter 'y'
Do you accept the license 'android-sdk-license-bcbbd656' [y/n]: y




Installing Archives:
  Preparing to install archives
  Downloading Android SDK Tools, revision 23.0.2
     (15%, 525 KiB/s, 2 minutes left))









As an Amazon Associate I earn from qualifying purchases.

Creating Google API key for Map v2

The key will be needed in AndroidManifest.xml like this... 

<meta-data
          android:name="com.google.android.maps.v2.API_KEY"

          android:value="AIz...jshdkfjhdsjkhfkdjsh..bMI"/>

To get the key go to:

https://code.google.com/apis/console/

1) create a NEW app (drop-down on the left Create...)
2) Select "Services" and turn on Maps...

3) API Access "Create new Android Key.." button

4) Terminal:
$ cd .android/
uki$ keytool -list -v -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android 
Alias name: androiddebugkey
Creation date: Nov 23, 2011
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 4ecdba20
Valid from: Wed Nov 23 21:29:36 CST 2011 until: Fri Nov 15 21:29:36 CST 2041
Certificate fingerprints:
MD5:  7E:FA:01...fkdjsflkjdlksjflkdsjlfjdsljfljlkdsf....:49:61:36
SHA1: D0:5...sdjkflkdsjflkjsdklfjdsljkdsl....F:A1:43
Signature algorithm name: SHA1withRSA
Version: 3
uki:.android uki$ 


5) Enter the SHA1 key, SEMICOLON; and PACKAGE NAME of your app



6) copy the successfully generated KEY to AndroidManifest.xml

Yay!








As an Amazon Associate I earn from qualifying purchases.

Apache Server on Mac OS 10.8

The Apache server is available on Mac by deploying your html pages to:

/Library/WebServer/Documents/

uki:Documents uki$ ls -alt /Library/WebServer/Documents/
total 80
...
-rw-r--r--  1 root  wheel   3726 Aug 24  2012 PoweredByMacOSX.gif
-rw-r--r--  1 root  wheel  31958 Aug 24  2012 PoweredByMacOSXLarge.gif
uki:Documents uki$

You start the Apache server by:
$ sudo apachectl start


Re-deploying your code:
remove old:
$ sudo rm -r /Library/WebServer/Documents/my_project
Make directory:
$ sudo mkdir /Library/WebServer/Documents/my_project
copy new code in:
$ sudo cp -r /Users/uki/Documents/workspaces/.../my_project/* /Library/WebServer/Documents/my_project

you can view your local server at:
http://localhost/


As an Amazon Associate I earn from qualifying purchases.

Setting JAVA_HOME variable on Mac

$ edit ~/.profile

add line

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

SAVE

re-open Terminal

$ echo $JAVA_HOME
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

$

Please note that the most current version (1.6) is loading when 1.7 is missing.


As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles