Operators & Redirection
Hash shell supports Unix operators for connecting and controlling commands.
Overview
| Operator | Type | Description |
|---|---|---|
| | Pipe | Connect stdout to stdin |
> | Redirect | Output to file (overwrite) |
>> | Redirect | Output to file (append) |
< | Redirect | Input from file |
2> | Redirect | Stderr to file |
&> | Redirect | Both stdout and stderr |
&& | Chain | Run if previous succeeded |
|| | Chain | Run if previous failed |
; | Chain | Run sequentially |
& | Background | Run in background |
Quick Examples
Pipes
ls | grep txt
cat file.txt | sort | uniq
ps aux | grep nginx | wc -l
Redirection
echo "Hello" > file.txt # Overwrite
echo "World" >> file.txt # Append
cat < input.txt # Input from file
command 2> errors.log # Stderr
command &> all.log # Both
Command Chaining
make && make install # Run if success
cd /nonexistent || echo "Failed" # Run if fail
echo "Start"; command; echo "End" # Sequential
Background
long_command & # Run in background
Learn More
- Pipes - Connect command output to input
- I/O Redirection - Control file input/output
- Command Chaining - Sequential and conditional execution
- Command Substitution - Use command output as arguments
- Background Processes - Run commands in background