✨ Rush Shell Features

Comprehensive POSIX sh-compatible shell with advanced expansions, powerful built-ins, and modern interface

🔧 Core Features

Command Execution

Execute external commands and built-in commands with full PATH resolution and error handling

# External commands
ls -la /tmp
curl https://api.example.com

# Built-in commands
cd /home/user
pwd
env
🔗

Pipelines

Chain commands using the pipe operator for powerful data processing workflows

# Basic pipelines
ls | grep ".txt" | wc -l
cat file.txt | sort | uniq

# Complex pipelines
find . -name "*.rs" | xargs grep -l "fn main" | head -5
📝

Redirections

Input and output redirections for flexible I/O handling in commands and scripts

# Output redirection
echo "Hello World" > hello.txt
ls -la >> log.txt

# Input redirection
sort < unsorted.txt > sorted.txt
grep "pattern" < file.txt
📄

Here-Documents & Here-Strings

Multi-line and single-line input redirection with full variable expansion support

# Here-document (multi-line)
cat << EOF
Line 1: $USER
Line 2: $HOME
EOF

# Here-string (single-line)
grep "pattern" <<< "search this text"
wc -w <<< "count these words"

🔄 Expansions

Brace Expansion

Generate multiple strings from patterns with braces - perfect for batch operations and file generation

Basic Lists

echo {a,b,c}
# Output: a b c

echo file{1,2,3}.txt
# Output: file1.txt file2.txt file3.txt

Numeric Ranges

echo {1..5}
# Output: 1 2 3 4 5

echo test{1..3}.log
# Output: test1.log test2.log test3.log

Alphabetic Ranges

echo {a..e}
# Output: a b c d e

echo file{a..c}.txt
# Output: filea.txt fileb.txt filec.txt

Real-World Usage

# Create multiple directories
mkdir -p project/{src,test,docs}

# Create numbered backup files
cp important.txt important.txt.{1..5}

# Generate test data
echo user{1..100}@example.com

Command Substitution

Execute commands and substitute their output inline within the current shell context for optimal performance

Basic Substitution

echo "Current dir: $(pwd)"
echo "Files: `ls | wc -l`"

# Variable assignments
PROJECT_DIR="$(pwd)/src"
FILE_COUNT="$(ls *.rs 2>/dev/null | wc -l)"

Advanced Usage

# Complex commands
echo "Rust version: $(rustc --version | cut -d' ' -f2)"

# Error handling
RESULT="$(nonexistent_command 2>/dev/null || echo 'failed')"

# Multiple commands
echo "Output: $(echo 'First'; echo 'Second')"

Arithmetic Expansion

Evaluate mathematical expressions using POSIX-standard $((...)) syntax with full operator precedence

Basic Arithmetic

echo "Result: $((2 + 3 * 4))"
echo "Division: $((20 / 4))"
echo "Modulo: $((17 % 3))"

Variable Integration

x=10
y=3
echo "x + y = $((x + y))"
echo "x squared = $((x * x))"

Complex Expressions

# With precedence
echo "2 + 3 * 4 = $((2 + 3 * 4))"        # 14
echo "(2 + 3) * 4 = $(((2 + 3) * 4))"    # 20

# Temperature conversion
celsius=25
fahrenheit=$((celsius * 9 / 5 + 32))

Parameter Expansion with Modifiers

Advanced variable expansion with POSIX sh modifiers for powerful string manipulation

Default Values

# Use default if unset or null
echo "Home: ${HOME:-/home/user}"
echo "Editor: ${EDITOR:-vim}"

# Assign default if unset
echo "Editor: ${EDITOR:=nano}"

Substring Operations

FILENAME="document.txt"
echo "Extension: ${FILENAME:9}"           # "txt"
echo "Name only: ${FILENAME:0:8}"         # "document"
echo "Length: ${#FILENAME}"               # "13"

Pattern Operations

# Remove file extensions
echo "No extension: ${FILENAME%.txt}"

# Remove directory paths
FULL_PATH="/usr/bin/ls"
echo "Basename: ${FULL_PATH##*/}"         # "ls"

# Pattern substitution
echo "Replaced: ${TEXT/old/new}"

Indirect Expansion (bash extension)

# Basic indirect expansion
VAR_NAME="MESSAGE"
MESSAGE="Hello World"
echo "Value: ${!VAR_NAME}"                # "Hello World"

# List variables by prefix
MY_VAR1="a"
MY_VAR2="b"
echo "All MY_ vars: ${!MY_*}"             # "MY_VAR1 MY_VAR2"

🎮 Control Structures

Conditional Statements

If Statements

if [ -f "/etc/passwd" ]; then
    echo "File exists"
elif [ -d "/etc" ]; then
    echo "Directory exists"
else
    echo "Neither exists"
fi

Case Statements

case $filename in
    *.txt|*.md) echo "Text file" ;;
    *.jpg|*.png) echo "Image file" ;;
    file?) echo "Single character file" ;;
    [abc]*) echo "Starts with a, b, or c" ;;
    *) echo "Other file type" ;;
esac

Loops

For Loops

for i in 1 2 3 4 5; do
    echo "Number: $i"
done

for file in *.txt; do
    echo "Processing: $file"
    wc -l "$file"
done

While Loops

count=1
while [ $count -le 5 ]; do
    echo "Count: $count"
    count=$((count + 1))
done

Functions

Function Definition

myfunc() {
    echo "Hello $1!"
    local result=$(( $2 + $3 ))
    return $result
}

# Call function
myfunc "World" 2 3
echo "Exit code: $?"

Function Introspection

# List all functions
declare -f

# Show specific function
declare -f myfunc

# Local variables
local var="value"

🛠️ Built-in Commands

Rush includes 20 comprehensive built-in commands for enhanced functionality and performance:

Process Management

  • cd - Change directory
  • exit - Exit the shell
  • pwd - Print working directory

Variable Management

  • env - List environment variables
  • export - Export variables to child processes
  • unset - Remove variables
  • shift - Shift positional parameters

Directory Stack

  • pushd - Push directory and change
  • popd - Pop directory and change
  • dirs - Display directory stack

Alias Management

  • alias - Define or display aliases
  • unalias - Remove alias definitions

Script Execution

  • source / . - Execute script files
  • test / [ - Conditional logic tests

Signal Handling

  • trap - Set signal handlers and traps

Interface

  • help - Show available commands
  • set_colors - Control color output
  • set_color_scheme - Switch themes
  • declare - Function introspection

🚀 Advanced Features

🎨

Color Support

Modern terminal interface with customizable color schemes and accessibility support

# Runtime color control
set_colors on
set_color_scheme dark

# Accessibility support
export NO_COLOR=1
📁

Tab Completion

Intelligent completion for commands, files, directories, and nested paths

# Command completion
cd → cd, env, exit

# File completion
cat f → cat file.txt

# Path completion
ls src/m → ls src/main/
⚙️

Configuration

Automatic sourcing of ~/.rushrc for personalized shell environment

# ~/.rushrc
export EDITOR=vim
alias ll='ls -la'
echo "Welcome to Rush!"
📊

Performance

Optimized execution with in-context command substitution and efficient expansions

# 10-50x faster for builtins
echo "Fast: $(echo 'hello')"

# Efficient brace expansion
echo {1..1000} | wc -w