The Problem After the cd command, the next command is almost always ls so we want to combine the two to automatically issuing the ls command right after the cd command. The Solution In bash, add the following line in either ~/.bash_profile or ~/.bashrc: If you are using csh or tcsh, add the following line […]
January 11, 2011
The Problem In my bash script, I would like to print both the the standard output (typically the screen) and a file. The Solution Below is a simple script which demonstrate the solution. Discussion Normally, the output from a bash script goes to the standard output, typically the screen. To redirect the output to both […]
March 24, 2010
The Problem I want to login to a remote Linux machine via SSH and to be in the same directory I was before my last log out. The Solution Since my login shell is bash, I present this solution in bash, but you can adapt it for your favorite shells. This tip relies on the […]
January 13, 2010
The Problem Bash does not have a “confirm” command to solicit the user’s confirmation of an action. I realize that some commands, such as rm which can ask for the user’s confirmation via the -i flag, but many do not. In addition, when writing bash scripts, I often run into situations which requires the confirmation […]
October 11, 2009
The Problem While I know about the Ctrl-R key combination in bash to perform an incremental reverse search the history; I often need to grep the history to find what I want. For example, to find out what directory I changed into, I issue the following command: That’s a lot of typing for a lazy […]
September 18, 2009
The Problem I want a quick and dirty way to parse command line from my bash script. For example: myscript.sh --file foo.txt --width 72 The Solution The method is truly quick and dirty, but before we dive right in, let’s make a few assumptions: Each flag must be followed by a value. That means –debug […]
September 10, 2009
The Problem Sometimes, I need a simple menu in bash, but I don’t want to spend a good deal of time coding for one. The Solution Bash has a built-in command called select which gets the job done. To demonstrate this command, I am going to write a short bash script. This script lists all […]
April 26, 2011
0