Difference between revisions of "Installation/Working with the Shell"

From OpenFOAMWiki
m (Learning how to use a shell: typo)
(Introduction: Save current changes, before something breaks...)
Line 16: Line 16:
 
** {{tt|Ctrl+Shift+V}} - Paste what's on the [http://en.wikipedia.org/wiki/Clipboard_%28computing%29 clipboard memory], to the terminal's shell.
 
** {{tt|Ctrl+Shift+V}} - Paste what's on the [http://en.wikipedia.org/wiki/Clipboard_%28computing%29 clipboard memory], to the terminal's shell.
 
** {{tt|Shift+Insert}} - Same as the previous command, namely it pastes what's on the clipboard.
 
** {{tt|Shift+Insert}} - Same as the previous command, namely it pastes what's on the clipboard.
 +
* Do not forget that the shell environment on Linux and other [http://en.wikipedia.org/wiki/POSIX POSIX] Operating Systems are case-sensitive! This means that, for example, the following two commands are considered different:
 +
** {{tt|icoFoam}} - this command exists when OpenFOAM is properly installed.
 +
** {{tt|icoFOAM}} - this doesn't exist... at least not on a ''normal'' installation of OpenFOAM.
 +
 +
== Learning how to manipulate the environment ==
 +
In this section the objective is to understand how the shell environment works. This is a necessary learning step for understanding how you can take advantage of OpenFOAM's way of interacting with the shell.
 +
 +
In essence, the shell environment is a memory space where variables are defined, so that programs know where they are working and what they can or even should do. These variables can be defined in two ways:
 +
<ol>
 +
<li>Mainly for local usage, which they are visible only for the current shell environment. In other words, the variable won't be shared with a script or application you run the the current shell. Examples:
 +
<bash>MY_VARIABLE=A sentence or path to something or even a value
 +
X=1
 +
y=2
 +
MY_OTHER_HOME=/home/school</bash></li>
 +
<li>For global usage, but only in the sense that all applications launched from this shell will henceforth know that said variable has got that particular value assigned. This is the main type of shell variables used by OpenFOAM. Examples on bash:
 +
<bash>MY_VARIABLE=A sentence or path to something or even a value
 +
export MY_VARIABLE
 +
 +
export X=1
 +
export y=2
 +
export MY_OTHER_HOME=/home/school</bash></li>
 +
</ol>
 +
 +
You can see and use these variables in the following ways:
 +
; {{tt|echo $MY_OTHER_HOME}}
 +
: This shows you what the variable {{tt|MY_OTHER_HOME}} contains.
 +
; {{tt|ls -l $MY_OTHER_HOME}}
 +
: This shows the folder contents of the path defined in that variable, assuming said path exists.
 +
; {{tt|cd $MY_OTHER_HOME}}
 +
: This will change directory to that path you've just checked.
 +
 +
There are a few more commands you should learn to understand how manipulate and make use of these variables:
 +
; {{tt|source}}
 +
: This command runs a script as if you were typing the commands yourself directly on the current shell environment. Another name for this specific command is the dot/period symbol '''{{tt|.}}''' which does basically the same, but it's only accessible on some shells. For example, the following two commands are identical on {{tt|bash}}:
 +
<bash>source ~/OpenFOAM/OpenFOAM-2.1.1/etc/bashrc
 +
. ~/OpenFOAM/OpenFOAM-2.1.1/etc/bashrc</bash>
 +
 +
; {{tt|env}}
 +
: This command is a quick way to see what variables currently are defined in the current shell environment. The {{tt|env}} command can do a lot more than this, but that's for you to later study for yourself which you can check by running: <bash>man env</bash>
 +
 +
; {{tt|export}}
 +
: As already shown in examples above, this defines a shell variable as globally seen on the current shell. When executed alone, it shows what variables have been ''exported'' and are available.
 +
 +
; {{tt|alias}}
 +
: This command is useful for creating aliases to long commands you usually use. (TODO: finish this item)
  
 
= OpenFOAM Environment Variables =
 
= OpenFOAM Environment Variables =

Revision as of 13:27, 9 September 2012

1 Introduction

This page attempts to introduce the reader to getting to know what a shell is and how said shells work in terminals or consoles.

On a second part, introduces the reader to getting to know how to use OpenFOAM in said shells.

The text may seem rather informal, so feel free to improve this wiki page!

1.1 Learning how to use a shell

Well, this section will seem to be rather lazy to you, but it's best to point the reader to one of the best tutorials there is on this subject, namely: Learning the shell

There you'll learn all of the necessary basics on how to use the shell to your benefit. Additionally, here are a few more essential hints:

  • Today's terminal/consoles used in modern Linux Distributions have interactive mouse and keyboard controls. You can find out which are they by checking the menus on them, as well as learning from there some of the keyboard shortcuts you can use.
  • Some examples of keyboard shortcuts:
    • Ctrl+Shift+C - Copy selection from the terminal/console window.
    • Ctrl+Shift+V - Paste what's on the clipboard memory, to the terminal's shell.
    • Shift+Insert - Same as the previous command, namely it pastes what's on the clipboard.
  • Do not forget that the shell environment on Linux and other POSIX Operating Systems are case-sensitive! This means that, for example, the following two commands are considered different:
    • icoFoam - this command exists when OpenFOAM is properly installed.
    • icoFOAM - this doesn't exist... at least not on a normal installation of OpenFOAM.

1.2 Learning how to manipulate the environment

In this section the objective is to understand how the shell environment works. This is a necessary learning step for understanding how you can take advantage of OpenFOAM's way of interacting with the shell.

In essence, the shell environment is a memory space where variables are defined, so that programs know where they are working and what they can or even should do. These variables can be defined in two ways:

  1. Mainly for local usage, which they are visible only for the current shell environment. In other words, the variable won't be shared with a script or application you run the the current shell. Examples:
    MY_VARIABLE=A sentence or path to something or even a value
    X=1
    y=2
    MY_OTHER_HOME=/home/school
  2. For global usage, but only in the sense that all applications launched from this shell will henceforth know that said variable has got that particular value assigned. This is the main type of shell variables used by OpenFOAM. Examples on bash:
    MY_VARIABLE=A sentence or path to something or even a value
    export MY_VARIABLE
     
    export X=1
    export y=2
    export MY_OTHER_HOME=/home/school

You can see and use these variables in the following ways:

echo $MY_OTHER_HOME
This shows you what the variable MY_OTHER_HOME contains.
ls -l $MY_OTHER_HOME
This shows the folder contents of the path defined in that variable, assuming said path exists.
cd $MY_OTHER_HOME
This will change directory to that path you've just checked.

There are a few more commands you should learn to understand how manipulate and make use of these variables:

source
This command runs a script as if you were typing the commands yourself directly on the current shell environment. Another name for this specific command is the dot/period symbol . which does basically the same, but it's only accessible on some shells. For example, the following two commands are identical on bash:
source ~/OpenFOAM/OpenFOAM-2.1.1/etc/bashrc
. ~/OpenFOAM/OpenFOAM-2.1.1/etc/bashrc
env
This command is a quick way to see what variables currently are defined in the current shell environment. The env command can do a lot more than this, but that's for you to later study for yourself which you can check by running:
man env
export
As already shown in examples above, this defines a shell variable as globally seen on the current shell. When executed alone, it shows what variables have been exported and are available.
alias
This command is useful for creating aliases to long commands you usually use. (TODO: finish this item)

2 OpenFOAM Environment Variables

TODO: ...

3 Advanced Topics

3.1 OpenFOAM Shell Environment

TODO: ... copy stuff from my blog post: http://www.cfd-online.com/Forums/blogs/wyldckat/931-advanced-tips-working-openfoam-shell-environment.html

3.2 Searching for files

TODO: ...