Skip to content
Snippets Groups Projects
unix-shells.md 3.64 KiB
Newer Older
# Terminals and Shells

## Content ideas

### 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*
                - 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`)