Getting started with MSYS

From gvSIG CE Wiki

Jump to: navigation, search

Working with MSYS and MinGW is like working on a Linux command line and can feel strange at first to Windows users. However, you will soon discover that the command line interface (shell) that comes with MSYS (the bash) is very convenient and not hard to use at all (a lot less cumbersome to use, in fact, than cmd.exe).

Start the shell by running C:\msys\msys.bat.

You will find some important hints below. These hints have been written with Windows users and MSYS in mind. However, most of them also apply to Linux and Mac OS X, which come with a built-in Terminal and shell.

Contents

Issuing commands

  • You can recall old command using cursor up. This command history is saved between sessions.
  • Right-click the terminal window title to get configuration options, copy and paste text.

Navigating the file system

  • MSYS uses "/" to separate file and directory names, not "\" (like in Windows).
  • MSYS uses a Unix directory structure, which knows no drive letters and has its root (top level folder) simply at "/". But other than that, you can use the cd command, just like in cmd.exe to navigate through folders (aka directories).
  • The MSYS root directory ("/") is really the folder into which you installed MSYS. So this command would place you into the MSYS installation folder:
 cd /
  • Since you cannot go up higher than "/", you cannot "jump outside" the MSYS installation folder. Instead, you can use virtual drive letters to get to a Windows drive. E.g. this would take you to C:\:
 cd /c/

File commands

All of the below have a "--help" option that will display full usage information for the command.

  • ls lists the contents of the current directory (like DOS' dir).
  • mkdir <dir-name> creates a new directory.
  • cp <source> <target> copies a a file or directory. Append the "-R" to copy a directory with its entire contents.
  • mv <source> <target> moves or renames a file or directory.
  • rm <file|dir> removes a file or directory. You can, of course, use wildcards. In addition, the flag "-r" removes things recursively (i.e. all files and subfolders in a folder), and "-f" forces the removal, i.e. will not ask for confirmation. E.g. to immediately remove a folder myFolder, including all its contents, do:
 rm -rf myFolder

Be very careful with rm -rf! Everything you remove with rm will be gone for good. You cannot retrieve it from the Windows trashcan!

Environment variables

  • You can see a list of all environment variables by just typing:
 export
  • To set an environment variable to a new value, use (it is convention to write variable names all upper case):
 export VARIABLE="My value"
  • The value of a variable can be retrieved by prefixing it with "$":
 echo $PATH
  • To remove a variable from the environment:
 unset VARIABLE
  • Type in names of variables, etc. exactly as given, including upper and lower case. POSIX systems are case sensitive, and "myVariable" is not the same as "MYVariable"!

General advice

  • Executable files are in standard folders named bin. They will be found in there, no matter what the current directory is. If you have an executable in another directory, you can start it by cd'ing into that directory and then:
 ./<program>
  • The environment variable PATH has the names of all folders that will be searched for executable files. You can append additional folders to it (use ":" colon to separate entries):
 export PATH=$PATH:/my_folder/bin:
  • To avoid trouble with white space, enclose complex option values in " (quotation marks). E.g.:
 cd "my folder with spaces in its name"
  • But generally avoid white space in file and folder names!
  • You can kill any program that's running in the shell by pressing ctrl+c

Further reading

To learn more about the bash, please refer to one of the many excellent sources on the Internet.

http://www.beforever.com/bashtut.htm (quick introduction)

http://tldp.org/LDP/Bash-Beginners-Guide/html/ (more details)

Next steps

Continue with Compiling the C/C++ support libraries.

Previous steps

Go back to Setting up the GNU Compiler Collection.