sh + python

What is SHython?

SHython is a versatile shell having features of both bash and python. Bash is an excellent shell, well suited for executing commands and traversing the file system. However, the scripting language in bash is quite restrictive and unintuitive. Python is an excellent scripting language known for its intuitive (pythonic) design. In SHython, the scripting language component of bash is replaced with python making it an ideal shell. It should run on any system having bash and python (version >= 2.3).

Features of SHython

Other attempts at integrating bash and python exist and can be found by searching the web. However, at the time of launching SHython (May 2005), these attempts were very elementary and far from complete. In SHython, we have attempted to provide most of the commonly used features of bash. Following is a list of features that are currently present. More will be added in future.
  1. Command line: The interface for editing the command line input similar to a linux shell (like bash) with command history.
  2. Command prompt can be changed by changing the variables PY_PS1 and PY_PS2.
  3. Tab completion: Helps you to complete filenames, directories, shell commands, python modules and their attributes, usernames and shell-builtins by simply pressing the tab key.
  4. Aliasing: Allows to alias commands, functions and expressions. Provides you with alias and unalias builtins.
  5. Job control: Enables you to put processes in background and foreground and to stop currently running processes similar to bash. Provides you with builtins like fg, bg, jobs, etc.
  6. Advanced features: Piping and redirection of input and output streams for processes.
  7. Initialization script: A file ~/.pyshrc is executed before the pyshell is invoked. You can write down your regularly used aliases and functions in this file.
SHython constitutes less than 700 lines of code.

Rules and Guidelines

This section is a mini-tutorial. Reading this and the next sections should help you to get started using SHython very quickly.
  1. When a keyword or command exists in both in python and shell, shell is given preference over python. The priority of execution is shell, builtins and then python. So avoid using shell commands, builtins etc. as python variables.
  2. All programming constructs such as loops, conditional statements are in python.
  3. Embedding :
  4. While using the alias command the keyword alias is followed by the alias and the aliasing expression separated by a = sign. E.g. alias ls = ls --color=tty.
  5. The functions defined in the .pyshrc file are to be ended with an empty line.

Examples of Usage


Welcome to SHython!!

linux@mirage$ PY_PS1='SHython@\h'
SHython@mirage$ PY_PS2='---'
SHython@mirage$ ls | grep py > asdf; cat asdf &
[1] 13283


[1]  Done               cat asdf

SHython@mirage$ a=`echo $(`ls|grep py`) `
SHython@mirage$ cat $a
SHython@mirage$ word=`ls|grep .py`
SHython@mirage$ word=str(`echo $word`)
SHython@mirage$ for i in word:
           ---     print i


SHython has been developed by T.Kedarnath and G.Lakshmi as a semester project under the guidance of Dr.Vikram Pudi at the International Institute of Information Technology, Hyderabad, India.
SHython is currently hosted at