0

I'm pretty new to shell scripting and linux in general. Basically, I need to change the configuration file for logging out so that when a user logs out, a certain shell script is run.

Now, I've located the logout configuration file and opened it with vi using this command

$ vi ~/.bash_logout

At this point, I'm experiencing some very weird behavior. When I try to type a character, the cursor jumps around seemingly erratically. What could this be due to? I'm running the latest version of ubuntu.

And once I get that figured out, what's the command to run a .sh file from within this configuration file?

3
  • So... are you having trouble using vi then? Commented Oct 7, 2011 at 6:44
  • If the editor is really your problem, and all you need it for is to put a single command in your .bash_logout, you might as well do it from the command line. For example, if your logout action is echo bye you could do echo "echo bye" >>.bash_logout. Commented Oct 7, 2011 at 10:36
  • On ubuntu, you should be able to type edit ~/.bash_logout and a new window will open with a 'nicer' text editor. Gedit, I believe. Commented Oct 7, 2011 at 17:19

3 Answers 3

3

If you're having trouble with vi, try using nano instead. nano .bash_logout

If you do need to use vi for some reason, "i" will put the editor into insert mode, and ESC will take it out of insert mode when you're done. ":wq" will write and quit the editor.

To run a command, just put it in the .bash_logout file as you would type it on the commandline.

Sign up to request clarification or add additional context in comments.

4 Comments

And remember to ensure that the script is executable, and if you do not use a full pathname to the script, then ensure it is stored in a location listed on your PATH.
@JonathanLeffler: .bash_logout is like .bashrc, .profile and others. These don't need to be executable and they must be in the user's home. These files are not executed as normal scripts, they are executed with source (see help source) as if the user has typed the commands. The difference: Normal scripts cannot changes the local environment, cannot define aliases, cannot change the current working directory. The mentioned files can do that.
@A.H. Yes - it is the script run from the .bash_logout file that must be executable and in an appropriate location. The asker seems to be planning to have this execute in other people's environments, and I for one set my PATH the way I want (and would probably remove someone else's contributed .bash_logout from my home directory), so there may be problems with getting the script run.
@JonathanLeffler: Ok, NOW I understand. I've read over that part in the question. Thanks and sorry for that.
1

Some other useful commands:

  • a insert after selected character
  • o insert at next line
  • O insert at previous line
  • r replace a single character
  • R replace mode
  • :q! quit without saving
  • :w save
  • :wq save and quit

To get familiar with Vi and its brother Vim ("VI improved") I recommend the book "A Byte of Vim", you can read it online or download for free at http://www.swaroopch.com/notes/Vim

1 Comment

Don't forget the immensely memorable: 'type l (ell) to move the cursor right one character'.
0

You can permanently change your editor option. To find out what your current one is, type this:

export | grep -i edit

To change it on Ubuntu:

sudo update-alternatives –config editor

On any other BASH prompt, just do this:

export EDITOR="nano"

Replace 'nano' with 'vi', 'emacs', or any other preferred editor. You can also add this to your .bashrc by typing the following:

echo 'EDITOR="nano"' >> ~/.bashrc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.