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.
SHython constitutes less than 700 lines of code.
- Command line: The interface for editing the command line input similar to a linux shell (like bash) with command history.
- Command prompt can be changed by changing the variables PY_PS1 and PY_PS2.
- 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.
- Aliasing: Allows to alias commands, functions and expressions. Provides you with alias and unalias builtins.
- 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.
- Advanced features: Piping and redirection of input and output streams for processes.
- 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.
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.
- 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.
- All programming constructs such as loops, conditional statements are in python.
- Embedding :
- In order to embed python code in a shell command enclose it within braces headed by a $. For e.g. $a or $(some code) etc.
- In order to embed shell command in python expression enclose it within back quotes. For e.g. a=`ls -a` etc.
- Nested embedding is also possible. i.e. code of one language can be embedded recursively into another part of code (of the other language) which itself is an embedded code.
- 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.
- The functions defined in the .pyshrc file are to be ended with an empty line.
Examples of Usage
Welcome to SHython!!
SHython@mirage$ ls | grep py > asdf; cat asdf &
 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