Squirrel Shell

Current version - 1.2.1 (2008-04-01)

Overview

Squirrel Shell is made as a cross-platform alternative to system shells like bash in *nix and command.com (cmd.exe) in MS Windows. It is based on Squirrel scripting language and features:

Cross-platform nature of Squirrel Shell lets users write one script and use it everywhere instead of writing several scripts for doing the same thing, but in different OS's.

As Squirrel is a generic scripting language, this gives users more power as they aren't limited to functionality, specific to some dedicated purpose.

Examples

Squirrel Shell Bash command.com (cmd.exe)
#!/usr/bin/squirrelsh
// Output simple text message
printl("Hello, world!");
#!/bin/bash
# Output simple text message
echo "Hello, world!"
@echo off
rem Output simple text message
echo Hello, world!
#!/usr/bin/squirrelsh
// Run another program
run("foo");
#!/bin/bash
# Run another program
foo
@echo off
rem Run another program
foo
#!/usr/bin/squirrelsh
// Work with command line parameters
run("foo", [ __argv[1], __argv[2] ]);
#!/bin/bash
# Work with command line parameters
foo $1 $2
@echo off
rem Work with command line parameters
foo %1 %2
#!/usr/bin/squirrelsh
// Multiply two 2x2 matrices
// It's possible to use matrices of any size
function matrix (w, h)
{
   local r = array(h);
   for (local i = 0; i < h; i++)
      r[i] = array(w, 0);
   return r;
}
local m1 = matrix(2, 2),
      m2 = matrix(2, 2),
      r  = matrix(2, 2);
r[0][0] = m1[0][0] * m2[0][0] + m1[0][1] * m2[1][0];
r[0][1] = m1[0][0] * m2[0][1] + m1[0][1] * m2[1][1];
r[1][0] = m1[1][0] * m2[0][0] + m1[1][1] * m2[1][0];
r[1][1] = m1[1][0] * m2[0][1] + m1[1][1] * m2[1][1];
#!/bin/bash
# Multiply two 2x2 matrices
# It's possible to use matrices of any size
# Based on code by Charles Duffy

# matrix (w, h)
function matrix()
{
   local i=0
   local current_array=( )
   while [ "$i" -lt "$(($1 * $2))" ]; do
      current_array[$i]=0
      i=$((i + 1))
   done
   echo "${current_array[@]}"
}

# m_idx (w, y, x)
function m_idx()
{
   echo "$(($1 * $2 + $3))"
}

m1=(`matrix 2 2`)
m2=(`matrix 2 2`)
r=(`matrix 2 2`)

r[$(m_idx 2 0 0)]=$((${m1[$(m_idx 2 0 0)]} * ${m2[$(m_idx 2 0 0)]} + ${m1[$(m_idx 2 0 1)]} * ${m2[$(m_idx 2 1 0)]}))
r[$(m_idx 2 0 1)]=$((${m1[$(m_idx 2 0 0)]} * ${m2[$(m_idx 2 0 1)]} + ${m1[$(m_idx 2 0 1)]} * ${m2[$(m_idx 2 1 1)]}))
r[$(m_idx 2 1 0)]=$((${m1[$(m_idx 2 1 0)]} * ${m2[$(m_idx 2 0 0)]} + ${m1[$(m_idx 2 1 1)]} * ${m2[$(m_idx 2 1 0)]}))
r[$(m_idx 2 1 1)]=$((${m1[$(m_idx 2 1 0)]} * ${m2[$(m_idx 2 0 1)]} + ${m1[$(m_idx 2 1 1)]} * ${m2[$(m_idx 2 1 1)]}))
@rem It's impossible

Squirrel Shell © 2006, Constantin "Dinosaur" Makshin
Squirrel © 2003-2006, Alberto Demichelis
SourceForge.net Logo Valid HTML 4.01 Transitional Valid CSS!