Erik Fredericks, frederer@gvsu.edu Fall 2025
Based on material provided by Erin Carrier, Austin Ferguson, and Katherine Bowers
Or, running multiple commands in a single line
Seperate with ; or &&
;
&&
date ; who ; whoami ; echo "Hi there!"
date && who && whoami && echo "Hi there!"
&
https://dev.to/bowmanjd/bash-execution-tips-for-shell-jockeys-and-script-fabricators-5dan
Use || to execute one command only when the previous one fails. Combine the above for conditional branching. Use ; to join two commands when you want the second to execute no matter the result of the first one. Use & to run the first job in the background while the next executes. Follow all with wait for a clean return to the command prompt
||
stdin
stdout
stderr
Redirect stdout to file:
ls -la > dir_contents
Redirect stderr to file:
ls -la 2> errors
Redirect file to stdin:
sort < my_file.txt
Redirect stdout to file and stderr to stdout:
command >output 2>&1
Redirect stdout to file and stderr to another file:
command >output 2>output.err
Redirect stderr to the void:
command 2> /dev/null
command = echo "Hi" or eccccho "Hi"
command
echo "Hi"
eccccho "Hi"
Send output of one command as input to another
command1 args | command2
cat file | sort
cat file | sort | uniq
cat file | sort | uniq > output.txt
echo "hello" & echo "world"
note: the first will log to f
create a file with random words do the above