# Terminals and Shells ## Content ideas ### The why and a general comparison of TUI vs GUI - why use terminal - only option - maths compute server doesn't allow you to remote desktop - related being light processes (no gui overhead) - base way of manipulating files and processes - making, moving, renaming... files and folders (directories) - modify environment variables - string together multiple processes - automating, scheduling - launching scripts - cron - motivations for those *nerds* - whole keyboard becomes buttons - learning curve - possible increase in efficiency - minimalism: programs, typically lighter and faster - want to look like a hacker - a look at gui alternatives - benefits - some things are just better - ui not limited to grid of characters - insert quote Bram Molenaar about gvim - example of git operations - browse log and revert to a specific revision - TUI: multi-step operation involving copying hash - GUI: look at log, click on revision, choose hard revert - alt to text scripting - visual editors - example: website making - wix - adobe dreamweaver - drawbacks - when it's an abstraction on text: - extra dependency - cost - difficulty moving - potentially less flexible - RPA (robotic processes automation) - program that automates interactions with GUIs - scripting alternative usually simpler/robust when possible ### General knowledge - Linux/unix - bash - other shells - new: zsh - new default on mac - trendy on linux - old - (bourne) shell - predecessor of bourne again shell (bash) - broadly a subset other shells *modulo edge case behaviours* - EXERCISE - case for targeting this shell for portability (`dash` is also quite fast) - EXERCISE - ksh, csh, tcsh, scsh - not very common - exist on some machines for legacy, licensing reasons - FreeBSD license is too liberal to include bash in the install - shells straying away from sh (fish) - attempt to give better interactive experience - not great solution for scripting - the pros don't carry over to scripting - less portable - Windows - cmd.exe - behaves similarly to unix shells - manipulates: - processes (from executables) - inputs and outputs (typically text): stdin(0), stdout(1), stderr(2) - arguments to executables - environment variables - the skin is different - different commands - which -> where - ls -> dir - mv -> move - rm -> del - different env vars - $PWD -> %CD% - $HOME -> %USERPROFILE% - many things are more - Cygwin/similar - bash but in windows - allows things built on linux to be ported to windows - SageMath - Lean3 - Maxima - powershell - available on Linux (powershell core) - (ba)sh commands available - looks are deceiving, cmd works much more similarly to unix shells - "powershell is great, but only when there exists a cmdlet for what you want to do" ### Practical tips - Terminal troubleshooting - Can't find program? - test `which/where program_name` - executable must be in PATH to be found - immediate fix attempt - find executable, paste whole thing into terminal - May fail if process expects other env vars to be set - add executable locations to PATH (global/user installation) - Installers in windows usually have an option to "add to path" = "allow terminal usage" - linux, mac: `~/.bashrc` `~/.zshrc` - windows: start > search "environment variables" - activate some environment - Some programs expect an "environment" to be set before using - linux, mac: `. <smth>` - virtual environments - conda - pipenv (python) - windows MSVC or other software suite expecting you to open specific terminal profile - terminal bugging out in program (colours/icons/text placement) - processes control colours and text placement via special chars in output, which requires a standard (which have evolved) - aside: illustrate difference between bash/terminal - problem: misunderstanding between process/shell and terminal - new terminal + old program : SSHing onto old machine - typical fix: `export TERM=xterm` - old terminal + new program : using trendy software in `cmd.exe` - windows terminal - different terminal font - other evironment variables (`COLORTERM`, `LANG`) - tips when working on remote machine