Command Chaining in Shell
Level 3114 keystrokes
&& runs the next command only if the previous one succeeded, || only if it failed, and ; always. The output shown assumes temp.txt does not exist; the date line varies.
Shell code
# && chain: each step runs only if the previous one succeeded# cd build stays in effect for the following lines1mkdir -p build && cd build && cmake .. && make# 2>/dev/null hides rm's error; || runs echo only if rm failed2rm temp.txt 2>/dev/null || echo "File not found"# ; runs date whatever happened before; the date shown varies3echo "Done" ; dateOutput
File not found Done Mon Jan 15 10:30:45 UTC 2024
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Shell code and how often they appear.
&× 6"× 4.× 3/× 2|× 2-× 1;× 1>× 1