TAB in terminal, more than just ``ls''

Gwailo

B.A. Economics (Hon)
I hit TAB in the terminal window by accident recently, and noticed that it returns a very nice little directory listing, much like "dir /w" in the days of yore with DOS. But when I do that it responds with a terminal bell.

What EXACTLY does TAB do in tcsh?
 
Tab is used in tcsh for the lazy typer(me).

lets say you want to change directories to /usr/local/bin

you could type

cd /uTAB/loTAB/bTAB and it would fill in the rest of the letters for you... assuming you don't have the anything in those particular directories that might also match...

example

/uTAB might match /usr but it could also match /utilities... that being the case, you would want to give it a bit more info... like /utTAB and it would find /utilities...

Since you hit tab with nothing typed in, tried to match everything and it showed you what it came up with by sort of listing it like the ls command would.
 
or in your current directory, if you have a file named reallylongfilename, you type vi rea<TAB>, and it will auto expand the filename for you. it also works for commands in your PATH. type niu<TAB>, it will expand to niutil.

now here comes the neat part. if there are two files in your directory, say longnname1 and longname2, and you type long<TAB>, then it will expand as far as it can, and then beep: longfilename. if you press <TAB> a second time, it will list all the possible matches and put you back on your command line right where you were. so you can navigate through very big directory structures. you type the first two letters, then press tab twice to see all matches, then add one more letter that you choose from the list, then tab again, etc.. you will get what you want very quickly.

so that s why it did ls for you. if you type tab twice, with nothing already on the command line, it can t expand any further. an empty space matches everything (not even a space. just nothing), and two tabs will show you everything that it matches: everything. hence it behaves like ls.

bash is even smarter. it can autocomplete commands, checking that the files are executable. it will also autocomplete man pages.
 
For the full list of what autocompletion options are set up by default, check out
/usr/share/init/tcsh/completions

For example, you can type
defaults read (tab)
And get a list of all the defaults domains you could possibly read.
 
Supposedly you oughta use bash because tcsh is, um, sucky. I had a web site that gave reasons for this but I don't remember what it was. If you want to try out bash, though, you can get it from Apple's "UNIX Apps" section of the Downloads page.

-the valrus
 
I have also read the reasons why 'tcsh' sucks, but in fact, they only say (and I think rightly so) that 'tcsh' sucks only for programming. Use 'bash' for shell scripting, but 'tcsh' is really great for interactive terminal fiddling.

FWIW, 'tcsh' autocompletion can also detect what program you are using and complete only the relevant files/dirs.


dani++
 
Remember Unix Neophytes.

sometimes, the antiquated, lowest common denominator is best to know.

Suppse you find yourself at an old VAX or DEC computer. There will be csh, and sh, maybe tcsh. There will be vi.

I doubt you would find ksh, bash, pico, ee, or any other tasty treats.

/end hacker rant

But I recommend reading the O'Reilly and Associates shell collections. Using csh and tcsh, Learning the korn shell, Learning and Using bash.

Good books, always at my desk.
 
tcsh is fine for autocompletion.
And if you wanna stick with tcsh and use bash for shell programming.. just start your script with:

#!/usr/local/bin/bash or whereever your bash is located.

Thomas
 
Back
Top