shell

Show SQLite tables from the Android command line shell (adb)

Android/SQLite FAQ: How do I show a list of SQLite database tables from the Android command line (adb shell)?

You can show a list of SQLite tables by starting the Android adb shell (command line tool), and then properly invoking the sqlite3 command. Here's an example of how this works, with comments shown before each command:

How to start the Android command line shell

Android FAQ: How do I start the Android command line tool (so I can interact with my Android emulator or device)?

You start the Android command line with the adb shell command:

adb shell

This makes at least two assumptions:

  1. You have the Android SDK installed.
  2. You have an Android emulator (or physical device) running.

When you start the adb shell, you'll see a very simple prompt that looks like this:

Debug Linux shell scripts with -x

If you ever need to debug a Unix or Linux shell script, you can just add the -x option to the interpreter when you invoke it. You can add the shell's debug option on the command line like this:

sh -x misbehaving_script.sh

or at the end of the first line in your shell script (the she-bang line), like this:

#!/bin/sh -x

I was just working on a shell script related to fonts on a Mac OS X (Unix), system, and when I tried to run it normally, all it gave me was this error message:

A sample Mac OS X Bash startup file (.bash_profile)

In case anyone needs a sample .bash_profile startup file for their Mac OS X or other Unix/Linux system, I thought I'd share my most recent version here.

Linux shell script heredoc example

I was just working on my Linux Teleport command (Linux cd command with a history), and ran across the code below, which essentially shows how to use a form of "heredoc" syntax in a Bash shell script. This approach uses the Linux cat command, but functions just like the heredoc syntax in languages like Perl.

Here's the source code I just came across:

Linux shell script date formatting

Linux date FAQ: How do I create a formatted date in Linux? (Most likely, "How do I create a formatted date I can use in a Linux shell script?")

I just ran into a case where I needed to create a formatted date in a Linux shell script, where the date format looks like this:

2010-07-11

To create this formatted date string, I just used the Linux date command, using the "+" sign to specify that I want to use the date formatting option, like this:

A MySQL database backup shell script

MySQL database backup FAQ: Can you share a Linux shell script that I can use to make a MySQL backup?

I currently have a collection of websites on several different servers (including GoDaddy and A2 Hosting web servers), so I was just spending some time trying to automate my MySQL database backups. To that end, I just created a MySQL shell script that I use on each Linux server to make my database backups, and I thought I'd share that script here.

How to run a sed command from the Linux command line

Linux sed FAQ: How do I run a Linux sed command from the command line?

I usually only use the Linux sed command in sed scripts, but today I needed to do something much easier than normal, and as I thought about how to run a sed command from the Linux command line, I had to pause for a few moments. Finally I remembered the sed command line syntax, and it looks like this:

sed 's/THE_DATE/2010-07-11/' < sitemap-orig.xml > sitemap.xml

This sed command can be read like this:

New, free Introduction to Unix and Linux tutorial

After having this on my "wish list" for many years, I finally took the time tonight to regenerate the pages for my "Free Introduction to Unix and Linux tutorial". The old format was just horrible, spread out among 285 small pages, and while this one still needs some work, it's about 1,000 times better than the old format, and comes in weighing only 13 large tutorial pages.

Some of the tutorial material is a little dated now, but these sections are still very relevant to today's Unix/Linux world:

Bash shell script - how to prompt and read user input

Unix/Linux bash shell script FAQ: How do I prompt a user for input from a shell script (Bash shell script), and then read the input the user provides?

Answer: I usually use the shell script "read" function to read input from a shell script. Here are two slightly different versions of the same shell script. This first version prompts the user for input only once, and then dies if the user doesn't give a correst Y/N answer:

Syndicate content