command line

Teleport - the Unix/Linux cd command, improved

Summary: By keeping a history of the directories you've visited, the Teleport command is an improvement on the Unix/Linux cd command. By having a memory, Teleport lets you jump from one directory to any previously visited directory, easily.

A few quick notes:

A Perl getopts example

Perl getopts FAQ: Can you demonstrate how to use the getopts function? (Also written as, "Can you demonstrate how to read Perl command line arguments?")

How to put SBT into offline mode with a command line setting

Scala SBT FAQ: How do I put SBT into "offline mode" so I can use it while working on an airplane, or any other location where I don't have a WiFi connection?

Use this setting at the SBT command prompt:

> set offline := true

Warning: I honestly don't know how well this works. I have tried it a few times, and I know it prints out a ton of output, but I haven't paid attention to all that output to see exactly what it does.

To reverse the setting, just change it to false instead of true:

How to add a new jar file to the Scala REPL classpath (interactive command line)

Scala REPL FAQ: How do I add a Jar file to the Scala REPL classpath? (The Scala REPL is the interactive command line you get if you just type "scala" at your command line.)

To add a new jar file to the Scala REPL classpath (interactive command line classpath), use the ":cp" command at the command line, like this:

scala> :cp myjar.jar

After you do this, you should see a reply from the REPL like this:

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:

Reading Scala command line arguments

Scala command line FAQ: How do I read command line arguments (args) in a Scala shell script?

If your Scala shell script is very short, and you're not using an object or class declaration -- i.e., you have no main method -- you can access the script's command line arguments through the default args array, which is made available to you by Scala.

For instance, you can create a one-line Scala script named hello.scala like this:

Ruby command line arguments

Ruby FAQ: How do I read command line arguments in a Ruby script (Ruby command line args)?

To read command line args in a Ruby script, use the special Ruby array ARGV to get the information you need. Here are a few examples.

1) Getting the number of command line args

To get the number of command line arguments passed in to your Ruby script, check ARGV.length, like this:

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.

How to read shell script command line arguments

Unix/Linux shell script args FAQ: How do I access Unix or Linux shell script command line arguments?

If you're just expecting one or two parameters to be passed into a Unix or Linux shell script, and these parameters aren't options/flags to your script (like "-a" or "-f"), you can access the shell script arguments through variables named $1, $2, etc.

Here's a short example where I'm expecting two shell script command line arguments. If either of these command line arguments is blank, I display a usage statement and exit my script:

Syndicate content