Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Thursday, April 9, 2009

Cygwin ls command not found

If you are a linux enthusiast and really miss those greps and sed/awks on the windows box, you've probably installed cygwin. You tried running it either by double-clicking the cygwin icon on your desktop or the cygwin.bat file in your "C:\cygwin" directory and got the bash-3.X$ prompt. However, although the pwd or cd commands work, if you try ls, it says:"ls: command not found".

Here is what you need to do to fix it:
  1. Right click on "My Computer" -> Properties -> Advanced -> Environment Variables
  2. Add a new environment variable, called CYGWIN_HOME and set its value to C:\cygwin
  3. Edit the PATH environment variable and add C:\cygwin\bin to it (usually separated by a ';').
  4. Just click okay, exit any command prompts or bash shells (over cygwin) you may have open, and open it again - it'll work!
Note: this assumes that you have installed cygwin at C:\cygwin. If you've kept it someplace else, please modify the above accordingly.

Thursday, February 19, 2009

Command Spell Correction in Bash

If you tend to make mistakes while typing, bash can be a a little less than helpful; just spitting out a "No such file or directory." One small hack which helps towards this is the automatic spell correction built into bash. This will correct small typing errors made with the cd command as follows.

user@host:~ $ cd /ect
/etc
user@host:/etc$

It can be enabled for the current shell by

$ shopt -s cdspell

As before, you can make the effect more permanent by echoing the command into .bash_profile.

Wednesday, February 18, 2009

Case-insensitive Tab Completion in bash

Tab-completion is one of the major things which makes the command-line so powerfully fast to use. It has apparently been around for decades and its preliminary versions would even predate Unix. IMO, bash does it just right while the shells in Windows mess it up. However, many initial bash users find the shell too rigid and less suggestive. Here are a couple of ways I found which makes bash a bit more easy to use.

Most hardened Unix hackers tend to name all their files and directories in the lower case (to save on hitting shift), while less hardened users, especially those using GUI interfaces to browse their files use proper case. So if you are on the command-line and are not sure if the directory is Coursework or coursework, here's a hack for you. Just say:

$ set completion-ignore-case on

If you want to do this across sessions add this line to /etc/inputrc. You might want to do that as root as below.

# echo set completion-ignore-case on >> /etc/inputrc