Squirrel Shell

Current version - 1.2.6 (2011-12-17)

Overview

Squirrel Shell is a cross-platform alternative to system shells like sh in Unix-like systems and cmd.exe (command.com) in Microsoft® Windows®. It is based on Squirrel scripting language which has these 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 OSes.

Since 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)]}))

Squirrel Shell © 2006-2011, Constantin Makshin
Squirrel © Alberto Demichelis
PCRE © University of Cambridge
zlib © Jean-loup Gailly and Mark Adler
SourceForge.net Logo Valid HTML 4.01 Transitional Valid CSS!