Archive

Posts Tagged ‘bash’

Working in the Bash shell

November 18th, 2010 No comments

A nice post on IBM.com on an introduction to bash shell.

Summary: Get an introduction to the Bash shell, which you can use on nearly any UNIX®-based operating system. Bash is a mature, powerful, yet easy-to-use shell that is freely available. This tutorial provides a brief history of Bash, which indicates how the Bash shell is different than some of the other popular UNIX shells, and also provides an overview of the major features available within Bash. Next, you’ll learn more about the UNIX file system, how to work with both directories and files, and several methods for customizing the appearance and behavior of Bash. Finally, the tutorial concludes with a discussion of the job control functionality of Bash.

Read the entire article.

Categories: General Tags:

BASH programmable completion

January 25th, 2010 No comments

Bash is probably the easiest and most user friendly shell that many beginners start up with.  Many veteran UNIX guys such as myself still use bash because it makes moving around a unix system and writing scripts effortless for some reason. I also like the history and command completion of bash and in my opinion compare to other shells, majority of the Linux users love bash too.

Recently I came across bash programmable completion which basically enhances command completion feature of bash even more.  “Imagine typing ssh [Tab] and being able to complete on hosts from your ~/.ssh/known_hosts files. Or typing man 3 str [Tab] and getting a list of all string handling functions in the UNIX manual. mount system: [Tab] would complete on all exported file-systemtis from the host called system, while make [Tab] would complete on all targets in Makefile.”

You can download it here and read more about loads of other cool features it comes with.

Categories: linux Tags:

bash command-line editing

January 10th, 2010 No comments

If you work on command-line often, then this reference guide is for you. This is a quick reference of emacs and vi while in command-line using bash as your shell. To enable command-line editing for vi is set -o vi and for emacs it is set -o emacs.

Emacs Editing Mode

  • CTRL-B – Move backward one character (without deleting)
  • CTRL-F – Move forward one character
  • DEL – Delete on character backward
  • CTRL-D – Delete on character forward
  • ESC-B – Move one word backward
  • ESC-F – Move one word forward
  • ESC-DEL – Kill one word backward
  • ESC-CTRL-H – Kill one word backward
  • ESC-D – Kill one word forward
  • CTRL-Y – Retrieve (“yank”) last item killed
  • CTRL-A – Move to beginning of line
  • CTRL-E – Move to end of line
  • CTRL-K – Kill forward to end of line
  • TAB – Attempt to perform general completion of the text
  • ESC-? – List the possible completions
  • ESC-/ – Attempt filename completion
  • CTRL-X / – List the possible filename completions
  • ESC- ~ – Attempt username completion
  • CTRL-X ~ – List the possible variable completions
  • ESC-$ – Attempt variable completion
  • CTRL-X $ – List the possible variable completions
  • ESC-@ – Attempt hostname completion
  • CTRL-X @ – List the possible hostname completion
  • ESC-! – Attempt command completion
  • CTRL-X ! – List the possible command completions
  • ESC-TAB – Attempt completion from previous commands in the history list
  • CTRL-J – Same as RETURN
  • CTRL-L – Clears the screen
  • CTRL-M – Same as RETURN
  • CTRL-O – Same as RETURN, then display next line in command history
  • CTRL-T – Transpose two chracters on either side of point and move point forward by one
  • CTRL-U – Kills the line from the beginning to point
  • CTRL-V – Quoted insert
  • CTRL-[ – Same as ESC
  • ESC-C – Capitalize word after point
  • ESC-U – Change word after point to all capital letters
  • ESC-L – Change word after point to all lowercase letters
  • ESC-. – Insert last word in previous command line after point
  • ESC-_ – Same as ESC.

Vi Editing Mode

  • DEL – Delete previous character
  • CTRL-W – Erase previous word
  • CTRL-V – Quote the next character
  • ESC – Enter control mode
  • h – Move left one character
  • l – Move right one character
  • w – Move right one word
  • b – Move left one word
  • W – Move to beginning of next non-blank word
  • B – Move to beginning of preceding non-blank word
  • e – Move to end of current word
  • E – Move to end of current non-blank word
  • O -Move to beginning of line
  • ^ – Move to first non-blank character in line
  • $ – Move to end of line
  • i – Text inserted before current character (insert)
  • a – Text inserted after current character (append)
  • I – Text inserted at beginning ofline
  • A – Text inserted at end of line
  • R – Text overwrites existing text
  • dh – Delete one character backwards
  • dl – Delete on character forwards
  • db – Delete one word backwards
  • dw -Delete one word forwards
  • dB – Delete one non-blank word backwards
  • dW – Delete one non-blank word forwards
  • d$ – Delete to end of line
  • d0 – Delete to beginning of line
  • k or – – Move backward one line
  • j or + – Move forward one line
  • G – Move to line given by repeat count
  • /string – Search backward for string
  • ?string – Search forward for string
  • n – Repeat search in some direction as previous
  • N – Repeat search in opposite direction of previous

These examples were taken from O’reilly bash book. It’s one of my favorite book and you can purchase it on amazon. It’s the best book available for scripting in bash in my opinion.

Categories: scripts Tags: