# Tab for File Completion: only as su, not as user



## steve_s (Feb 19, 2010)

Why, as user, can I not use the tab key to complete my filenames?  If I change to su/root, I can use the tab key just fine to complete a file name as I type it into the konsole, but as user (even in the wheel group) it won't let me tab to complete a filename.

Why is that?  Is there a way to change that?


----------



## DutchDaemon (Feb 19, 2010)

Tip 1: the shells are different (type [cmd=]echo $SHELL[/cmd]) -- note: the root shell on FreeBSD is csh, but actually tcsh (guess what the 't' stands for)
Tip 2: some shells have automatic tab completion, some shells can be set to use tab completion, some shells can't do it at all

See the manual for your specific shell(s) about this.


----------



## steve_s (Feb 19, 2010)

I'm going to guess "tab"? ;-)

Ok, how does one set it so that if I'm not in X the user can use tab completion?  I just typed in the konsole (I'm in kde right now) and got back /bin/sh...


----------



## fronclynne (Feb 19, 2010)

AFIK, sh(1) does not have tab completion*.  You can use /bin/[t]csh, or install something from /usr/ports/shells/ (linux users tend to like shells/bash, sometimes shells/zsh)

http://www.daemonforums.org/showthread.php?t=666


*if you come from linux, you may be unaware that linux's /bin/sh is usually just a static link to bash (or ash).


----------



## steve_s (Feb 19, 2010)

Okay...still confused.

I have a konsole open as user.  I run echo $SHELL and it says /bin/sh, and I don't have tab completion.

I change to su.  As su I run echo $SHELL and it says /usr/local/bin/bash, and I do have tab completion.

Aren't bash and sh the same thing?  So shouldn't I be able to have tab completion with user?  Or do I need to set something so that user has the ability to file complete with tab?

Edit: sorry, just read the other thread you linked too...



> People coming to FreeBSD from Linux sometimes don't realize that sh
> and bash are two different things. Unless you need some special feature
> of bash that isn't in sh, for example, the select loop, it is always
> best to write scripts using /bin/sh rather than /usr/local/bin/bash for
> ...



...guess i'll have to install another shell if I want tab completion....


----------



## fronclynne (Feb 19, 2010)

You obviously have bash, if you can use it, but please do not use it for root, it will cause problems later.  

tcsh(1) (/bin/csh is hard linked to /bin/tcsh

```
> ls -li /bin/*csh
81119 -r-xr-xr-x  2 root  wheel  358472 Jan  7 10:03 /bin/csh
81119 -r-xr-xr-x  2 root  wheel  358472 Jan  7 10:03 /bin/tcsh
```
) has tab completion.


----------



## paean (Feb 19, 2010)

For su, it's recommended to use a shell that's part of the base system. Trying to log in using a shell that didn't survive portupgrade creates a few issues. ( ; You may want to change that.

For your user account, go nuts and change it to your shell of choice (with tab completion, of course!).


----------



## steve_s (Feb 19, 2010)

Ok, as user I've got /bin/sh while as su I've got /bin/csh (which we've said is tcsh).  Can tab as su but not as user.

Tried to change user shell with this:
chsh -s /usr/local/bin/bash user

but can't get it to change for user, it is still /bin/sh.

So, how can I get it to change?  Am I missing something in my chsh command?  this experimentation is all via kde gui in konsole, if that's relevant.


----------



## z662 (Feb 19, 2010)

Login in as the user you want to change the shell for (non root user)  Then type 
	
	



```
chsh
```

Follow the prompts.  Should work fine.  If that doesnt work however you will need to edit your /etc/passwd file (most likely will automatically be done upon proper completion of 'chsh'

Dont forget to log out by typing 'exit' to let the new shell load.


----------



## z662 (Feb 19, 2010)

Just wanted to correct myself, there are no 'prompts' it will open up your default text editor.  Just change the line from /bin/sh (or whatever it says) next to shell and put in the path to bash.  'usr/local/bin/bash'  ....I had 'adduser' on the brain regarding the prompts.  My mistake.  In any event, you should find that 'chsh' is rather straightforward and easy to use.


----------



## phoenix (Feb 19, 2010)

steve_s said:
			
		

> I have a konsole open as user.  I run echo $SHELL and it says /bin/sh, and I don't have tab completion.



Correct.  /bin/sh does not support any advanced, interactive features like command history, tab completion, etc.  It's mainly used for writing shell scripts.  For example, the entire rc(8) system on FreeBSD is written in /bin/sh.



> I change to su.  As su I run echo $SHELL and it says /usr/local/bin/bash, and I do have tab completion.



No, no, no, no, a thousand times, no!  Do not change root's shell to anything under /usr/local.  Leave it be.  You shouldn't be running as root enough to care about root's shell.    If you really need a "root" account that uses bash, then set a password for user "toor", set the shell for "toor" to bash, and use that.

The first time you get a "can't boot to single-user because /usr/local won't mount and can't run bash", you'll understand.  



> Aren't bash and sh the same thing?



Not even close!  The Bourne Shell (sh) is (one of?) the original shell for Unix.  And it's primary purpose nowadays is for scripting.  The Bourne Again Shell (bash) is for interactive use, includes a bunch of extra features geared toward interactive use, pretends to be compatible with sh (but really isn't), and does things very differently from sh.

Linux users are the only ones who think sh and bash are the same.    And, they write "sh" scripts using a lot of bashisms, making them non-portable.


----------



## phoenix (Feb 19, 2010)

`$ chsh -s /path/to/shell`


----------



## steve_s (Feb 19, 2010)

Ok, i want to thank all of you for your help; it was a precise question and I got some very thorough exact answers.

su is back to what I had at first, which is /bin/csh.  I only have been using root to install things on this brand new system, hence how much I've needed it recently...

Yes, it did open in the default editor, which is vi which I suck at, so I just manually edited the /etc/passwd file so that the last line is (my username for this user on this computer is "user"):


> user:*:1001:0:User:/home/user:/bin/csh



...which makes it the same as su/root.  Now I've got my tab completion and it won't drive me crazy (crazier?) whenever I hit tab and it doesn't complete it...:e

Oh, phoenix, I tried chsh -s /path/to/shell and it yelled at me and said I had to indicate which user it was, so it had to look more like chsh -s /path/to/shell username.  But, even though that acted like it changed it, the only thing that worked was manually changing the /etc/passwd file as mentioned (thanks, z662).

Finally, I'd like to ask: of the last two FreeBSD installs that I've done (both from the 8.0 dvd) why does the user and root use two different shells?  Why wouldn't they both be /bin/csh by default?

Oh, well, just curious.  I've got my tabs and thats what I was looking for..thanks all!


----------



## phoenix (Feb 19, 2010)

steve_s said:
			
		

> Oh, phoenix, I tried chsh -s /path/to/shell and it yelled at me and said I had to indicate which user it was, so it had to look more like chsh -s /path/to/shell username.



By default, it changes the shell of the user running it.  If you run it as root, it may ask for a username.



> But, even though that acted like it changed it, the only thing that worked was manually changing the /etc/passwd file as mentioned (thanks, z662).



You have to logout and login again to pick up the change.



> Finally, I'd like to ask: of the last two FreeBSD installs that I've done (both from the 8.0 dvd) why does the user and root use two different shells?  Why wouldn't they both be /bin/csh by default?



You choose which shell to use when you create the user.


----------



## sixtydoses (Feb 20, 2010)

With csh you can include the following inside the ~/.cshrc file to have the tab completion feature.


```
set autolist
```

Or, 


```
set autolist=ambiguous
```

for more bash-like feeling (double tabbing).


----------



## steve_s (Feb 20, 2010)

Ah, thanks, phoenix...I'll monitor that more closely on the next install.

And, sixtydoses, come to think of it, I did set that up for user, but it didn't do anything to the tabbing until I made the other changes, go figure.

Thanks, all. :e


----------



## bmimatt (Nov 16, 2012)

> Finally, I'd like to ask: of the last two FreeBSD installs that I've done (both from the 8.0 dvd) why does the user and root use two different shells? Why wouldn't they both be /bin/csh by default?



Well, csh is here by default, bash or other shells must be installed.  csh is also a part of the basic /bin/ toolset and bash (and other shells) live in userland (/usr/local/bin/), hence csh as the default. 

Cheers,
Matt


----------



## SirDice (Nov 16, 2012)

Run *adduser -C* and set the default shell to tcsh(1).


----------



## kkt (Nov 16, 2012)

steve_s said:
			
		

> I'm going to guess "tab"? ;-)


You'd guess wrong.  It's for TOPS-20, the first modern timesharing OS.  TOPS-20 featured a command interpreter with command and filename completion in some ways even better than tcsh.  See the next to the last section of the tcsh man page.


----------

