Monday, December 27, 2010

How to execute a scirpt in Linux

A shell script can be executed using the following syntax
chmod +x script.sh
./script.sh

You can also run the script directly without setting the script execute permission
bash script.sh
or
source script.sh
or
. script.sh

In the last example we are using . (dot) or source command which reads and executes commands from filename in the current shell.
When a script is executed using either the bash command or the source (.) command, you don't have to set execute permission on script.

reference: http://www.cyberciti.biz

Monday, December 13, 2010

How to run a C++ program in linux

Install g++ (Ubuntu) or gcc-c++ (RedHat or fedora) package using 
apt-get or yum.
sudo apt-get install g++
or 
yum install gcc-c++
Write a C++ program using your favorite editor.
emacs hello_world.cpp
or
vi hello_world.cpp
or
gedit hello_world.cpp
 #include <iostream>  
  using namespace std; 
  int main() { 
 
      cout << "Hello World!\n";
         
      return 0;
  }
The following command will compile your program 
and create an executable called a.out
   g++ hello_world.cpp
The following command will execute your program.
  ./a.out
Congratulations! You are done!