Using Completion in the bash Shell


Using Completion in the bash Shell

One of the cool features of the bash shell is command argument completion, with which you can type just part of a command, press , and have bash complete the command for you (Code Listing 3.8).

Code Listing 3.8. In this example, we typed only the ls command followed by "cd pub" and pressed the key; bash completed the command for us.

bash-2.00$ ls Complete NewProject bogus2  ftp   puppy Completed    News   dead.letter  mail  temp Mail access   files   public_html  testme bash-2.00$ cd public_html/ bash-2.00$ 

To use completion in the bash shell:

1.

ls -l

Use ls -l to list the files in your current directory.

2.

cd pub

Type in a partial command, then press to complete the command. In this example, we typed the cd command and part of the public_html directory (truncated to pub in the example), then pressed to complete it (see Code Listing 3.8).

Tips

  • Completion works only if there's just one possible match to the letters you type before you hit . For example, if you type cd pu (for public_html) and there's another subdirectory called puppy, the shell will beep and wait for you to type in enough letters to distinguish the two subdirectories.

  • You can use completion to complete commands, directory names within commands, and nearly anything else you might enter that's sufficiently unambiguous.





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net