Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Autocomplete in Unix Shell

Autocomplete in Unix Shell

Autocomplete in Unix Shell


Does anyone know if unix have an autocomplete feature?
The user is asked to input something and the word auto completes?  Like the script will look at an existing file for reference?


RE: Autocomplete in Unix Shell

You do have an option to autocomplete by typing the escape key in csh or tab in bash/tcsh.  If your looking to have it go automatically then I don't know off hand.  You would probably have to write your own program in C to do this.  Also you have to catch all typed characters once the autocomplete feature begins to prevent adding extra, and probably wrong, characters.  You also have to deal with partial completions when the program can't disambiguate between choices with the same root of characters.  If anyone has something like this I would also be very interested.


RE: Autocomplete in Unix Shell

I would have tended to agree with bulldog on this ... but I've just tried it in ksh.  ksh filename autocomplete appears to work when used inside a read command.  In ksh, autocomplete is triggered by Esc-\ sequence.

Maybe not exactly what you want, but probably the best you can get without writing something specific yourself.


RE: Autocomplete in Unix Shell

To enable what they others have said, make sure you have the line

set -o vi

in your .profile or .login scripts. Then you can enjoy the vi editor commands (and more) right from the command prompt.

To envoke the editor, simply hit the ESC key. Just like going from input mode to command mode inside of vi. Some of the more useful key strokes:

ESC+\ = autocomplete, will complete upto the non-unique character.
ESC+* = space delimited list of all files that match the pattern you started with.
ESC+/str = search the commandline history for str.
ESC+n = search for the next occurance of str.
ESC+k = go back one in the commandline history.
ESC+j = go forward one in the commandline history.
ESC+$ = go to the end of the current line
ESC+0 = go to the beginning of the current line
ESC+i = return to insert mode
ESC+A = append to the end of the current line
ESC+I = insert from the beginning of the current line
ESC+fx = move cursor to the right until the next occurance of x
ESC+Fx = move cursor to the left until the next occurance of x
ESC+x = delete character under cursor and place it in the buffer
ESC+p = place the contents of the buffer after the cursor
(combining the last two keystrokes)
ESC+xp = transpose two characters (I use this alot)

Good luck, and keep trying diferent combinations, it is amazing the power of the Unix command line.

(Love is like PI - natural, irrational, endless, and very important.)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close