| Main Page | News | Downloads | Documentation | Contact | Links |
Squirrel Shell is made as a cross-platform alternative to system shells like bash in *nix and cmd.exe (command.com) in 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.
Squirrel is a generic scripting language. This fact gives users more power as they aren't limited to functionality specific to some dedicated purpose.
| Squirrel Shell | Unix shell | command.com (cmd.exe) |
|
#!/usr/bin/squirrelsh // Output simple text message printl("Hello, world!"); |
#!/bin/sh # 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/sh # 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/sh # 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 # Thanks to 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)]})) |
@echo off rem Multiply two 2x2 matrices rem Thanks to William Bettridge-Radford setlocal call :mulmat %1 %2 echo %mulmat% endlocal & goto :eof :mulmat rem return (matrix %1 * matrix %2) rem %1 = "a, b, c, d" rem %2 = "w, x, y, z" setlocal for /f "tokens=1-4 delims=, " %%a in (%1) do ( for /f "tokens=1-4 delims=, " %%w in (%2) do ( call :calc_mam %%a %%w %%b %%y call :save_mam call :calc_mam %%a %%x %%b %%z call :save_mam call :calc_mam %%c %%w %%d %%y call :save_mam call :calc_mam %%c %%x %%d %%z call :save_mam ) ) endlocal & set mulmat=%mulmat% & goto :eof :calc_mam rem return (%1 * %2) + (%3 * %4) setlocal set /a mam_1=%1*%2 set /a mam_2=%3*%4 set /a mam_3=%mam_1%+%mam_2% endlocal & set mam=%mam_3%& goto :eof :save_mam rem append the last mam value to mulmat if "%mulmat%"=="" ( set mulmat=%mam% ) else ( set mulmat=%mulmat%, %mam% ) goto :eof |
|
Squirrel Shell © 2006-2009, Constantin Makshin Squirrel © Alberto Demichelis PCRE © University of Cambridge zlib © Jean-loup Gailly and Mark Adler |
|