* Perl
* PHP
* Python
* Ruby
* Tcl
* ECMAScript
* Shell
* C
Common to all:
There are two ways to run a script, one by invoking the interpreter on the command line, and the other is to run it as a normal executable.
To mark a file as executable, use this command:
Code:
chmod +x
To run a script, run it like a normal program, if the script isn't in your $PATH variable, specify the path.
The packages to be install, an example program, and the running of it are given here.
Code:
./
Perl:
You don't need to install anything.
PHP Code:
#!/usr/bin/perl
#Save as "hw.pl"
print "Hello world!";
PHP Code:
chmod +x hw.pl
./hw.pl
You will need to install the php-cli package.
Code:
sudo aptitude install php5-cli
PHP Code:
#!/usr/bin/php
// Save as hw.php
echo "Hello world\n";
?>
Python:
Python is already installed.
Example program:
PHP Code:
#!/usr/bin/python
#Save as "hw.py"
print "Hello world!"
Ruby:
Install with:
Code:
sudo aptitude install ruby
PHP Code:
#!/usr/bin/ruby
# Save as "hw.rb"
puts "Hello world!";
Tcl:
Tcl is installed.
Example program:
PHP Code:
#! /usr/bin/tclsh
# Save as "hw.tcl"
puts "Hello World!"
ECMAScript
Note: ECMAScript isn't normally used this way.
You will need to install spidermonkey, which is the ECMAScript interpreter used by Firefox.
Code:
sudo aptitude install spidermonkey-bin
PHP Code:
#!/usr/bin/smjs
//Save as "hw.js"
print("Hello world");
Shell Scripts
Obviously, you have a shell installed.
Example program:
Code:
#!/bin/sh
# Save as "hw.sh"
echo "Hello world"
C:
Surprise! C is normally compiled, see FAQ: Compiling your first C or C++ programs if you want to learn how to use C. There is a very good C interpreter which you can use. It is also a compiler, and may be better than gcc in some cases.
You will need to install Tiny C Compiler (tcc), use:
Code:
sudo aptitude install tcc
PHP Code:
#!/usr/bin/tcc -run
#include
int main(int argv, char ** argv)
{
printf("Hello World\n");
return 0;
}
Read more:
http://ubuntuforums.org/showthread.php?t=692720
No comments:
Post a Comment