shell - doubility-sky/daydayup GitHub Wiki

In computing, a shell is a command-line interpreter which exposes access to an operating system's services. In general, operating system shells use either a command-line interface (CLI) or graphical user interface (GUI), depending on a computer's role and particular operation. It is named a shell because it is the outermost layer around the operating system.

Command-line shells require the user to be familiar with commands and their calling syntax, and to understand concepts about the shell-specific scripting language (for example, bash).

Learn

scripting

  • Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting
  • Shell 脚本编程30分钟入门
  • Shell 脚本传参方法总结
    echo $0    # 当前脚本的文件名(间接运行时还包括绝对路径)。
    echo $n    # 传递给脚本或函数的参数。n 是一个数字,表示第几个参数。例如,第一个参数是 $1 。
    echo $#    # 传递给脚本或函数的参数个数。
    echo $*    # 传递给脚本或函数的所有参数。
    echo $@    # 传递给脚本或函数的所有参数。被双引号 (" ") 包含时,与 $* 不同,下面将会讲到。
    echo $?    # 上个命令的退出状态,或函数的返回值。
    echo $$    # 当前 Shell 进程 ID。对于 Shell 脚本,就是这些脚本所在的进程 ID。
    echo $_    # 上一个命令的最后一个参数
    echo $!    # 后台运行的最后一个进程的 ID 号
  • useful scripts for making developer's everyday life easier and happier, involved java, shell etc.
  • Minimal safe Bash script template
  • Advanced Shell Scripting Techniques: Automating Complex Tasks with Bash

The Bourne shell was the default shell for Version 7 Unix. Unix-like systems continue to have /bin/sh—which will be the Bourne shell, or a symbolic link or hard link to a compatible shell—even when other shells are used by most users.

  • pure sh bible: A collection of pure POSIX sh alternatives to external processes.

Bash (the Bourne-Again shell)

Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been used as the default login shell for most Linux distributions and all releases of Apple's macOS prior to macOS Catalina. A version is also available for Windows 10 via the Windows Subsystem for Linux. It is also the default user shell in Solaris 11.

The Z shell (Zsh) is a Unix shell that can be used as an interactive login shell and as a command interpreter for shell scripting. Zsh is an extended Bourne shell with many improvements, including some features of Bash, ksh, and tcsh.

  • Moving to zsh
  • 你不需要花哨的命令提示符
  • Oh My Zsh is an open source, community-driven framework for managing your zsh configuration.
  • Antigen is a small set of functions that help you easily manage your shell (zsh) plugins, called bundles. The concept is pretty much the same as bundles in a typical vim+pathogen setup. Antigen is to zsh, what Vundle is to vim.
  • awesome-zsh-plugins: A collection of ZSH frameworks, plugins, tutorials & themes inspired by the various awesome list collections out there.

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells.

  • How To Use Screen
  • linux screen 命令详解
  • Frequently Command:
    screen -ls             列出当前所有的session
           -r <作业名称>    恢复离线的screen作业。
    
  • In Session Command:
    C-a n -> Next,切换到下一个 window 
    C-a p -> Previous,切换到前一个 window 
    C-a d -> detach,暂时离开当前session,
            将目前的 screen session (可能含有多个 windows) 丢到后台执行,
            并会回到还没进 screen 时的状态,此时在 screen session 里,
            每个 window 内运行的 process (无论是前台/后台)都在继续执行,即使 logout 也不影响。 
    
  • man screen

tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached.

  • Getting Started
  • Gentle Guide to Get Started With tmux
  • Getting started with Tmux
  • Tmux 使用教程
  • frequently used commands
    tmux ls                         # or `tmux list-session`
    tmux new -s <session-name>
    tmux at -t <session-name>       # or `tmux attach -t <session-name>`
    tmux rename-session -t <session-name> <new-name>
    tmux switch -t <session-name>
    tmux detach                         # or `C-b d`
    tmux kill-session -t <session-name>
    # inside a tmux session
    tmux new-window -n <window-name>    # or `C-b c`
    tmux rename-window <new-name>
    tmux select-window -t <window-name>
  • frequently used shortcuts (prefix key C-b):
    • C-b c Create a new window
    • C-b s List all sessions
    • C-b w List all sessions' windows
    • C-b n Next window in current session
    • C-b p Previous window in current session
    • C-b <0~9> Select window 0~9 in current session
    • C-b $ Rename current session
    • C-b t Show a clock
  • tmux shortcuts & cheatsheet - zh-CN
tmux help `C-b ?`
C-b Space   Select next layout
C-b !       Break pane to a new window
C-b "       Split window vertically
C-b #       List all paste buffers
C-b $       Rename current session
C-b %       Split window horizontally
C-b &       Kill current window
C-b '       Prompt for window index to select
C-b (       Switch to previous client
C-b )       Switch to next client
C-b ,       Rename current window
C-b -       Delete the most recent paste buffer
C-b .       Move the current window
C-b /       Describe key binding
C-b <0~9>   Select window 0~9
C-b :       Prompt for a command
C-b ;       Move to the previously active pane
C-b =       Choose a paste buffer from a list
C-b ?       List key bindings
C-b C       Customize options
C-b D       Choose and detach a client from a list
C-b E       Spread panes out evenly
C-b L       Switch to the last client
C-b M       Clear the marked pane
C-b [       Enter copy mode
C-b ]       Paste the most recent paste buffer
C-b c       Create a new window
C-b d       Detach the current client
C-b f       Search for a pane
C-b i       Display window information
C-b l       Select the previously current window
C-b m       Toggle the marked pane
C-b n       Select the next window
C-b o       Select the next pane
C-b p       Select the previous window
C-b q       Display pane numbers
C-b r       Redraw the current client
C-b s       Choose a session from a list
C-b t       Show a clock
C-b w       Choose a window from a list
C-b x       Kill the active pane
C-b z       Zoom the active pane
C-b {       Swap the active pane with the pane above
C-b }       Swap the active pane with the pane below
C-b ~       Show messages
C-b DC      Reset so the visible part of the window follows the cursor
C-b PPage   Enter copy mode and scroll up
C-b Up      Select the pane above the active pane
C-b Down    Select the pane below the active pane
C-b Left    Select the pane to the left of the active pane
C-b Right   Select the pane to the right of the active pane
C-b M-1     Set the even-horizontal layout
C-b M-2     Set the even-vertical layout
C-b M-3     Set the main-horizontal layout
C-b M-4     Set the main-vertical layout
C-b M-5     Select the tiled layout
C-b M-6     Set the main-horizontal-mirrored layout
C-b M-7     Set the main-vertical-mirrored layout
C-b M-n     Select the next window with an alert
C-b M-o     Rotate through the panes in reverse
C-b M-p     Select the previous window with an alert
C-b M-Up    Resize the pane up by 5
C-b M-Down  Resize the pane down by 5
C-b M-Left  Resize the pane left by 5
C-b M-Right Resize the pane right by 5
C-b C-b     Send the prefix key
C-b C-o     Rotate through the panes
C-b C-z     Suspend the current client
C-b C-Up    Resize the pane up
C-b C-Down  Resize the pane down
C-b C-Left  Resize the pane left
C-b C-Right Resize the pane right
C-b S-Up    Move the visible part of the window up
C-b S-Down  Move the visible part of the window down
C-b S-Left  Move the visible part of the window left
C-b S-Right Move the visible part of the window right

Zellij is a workspace aimed at developers, ops-oriented people and anyone who loves the terminal. At its core, it is a terminal multiplexer (similar to tmux and screen), but this is merely its infrastructure layer.

Tools

  • shellcheck, a static analysis tool for shell scripts https://www.shellcheck.net
  • explainshell is a tool (with a web interface) capable of parsing man pages, extracting options and explain a given command-line by matching each argument to the relevant help text in the man page. http://www.explainshell.com/
  • cheat allows you to create and view interactive cheatsheets on the command-line. It was designed to help remind *nix system administrators of options for commands that they use frequently, but not frequently enough to remember.
  • cli is a simple, fast, and fun package for building command line apps in Go. The goal is to enable developers to write fast and distributable command line applications in an expressive way.
  • Generic Colouriser is yet another colouriser (written in python) for beautifying your logfiles or output of commands.

alternative

  • CLI: improved - zh-CN
  • Modern Unix: A collection of modern/faster/saner alternatives to common unix commands.
  • fzf is a general-purpose command-line fuzzy finder.
  • When You Should Use Bash Over Python
  • sh Python process launching http://amoffat.github.com/sh
  • xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt. The language is a superset of Python 3.5+ with additional shell primitives. xonsh (pronounced conch) is meant for the daily use of experts and novices alike.
  • sarge, a wrapper for subprocess which aims to make life easier for anyone who needs to interact with external applications from their Python code.
  • (:warning:May be outdated)Plumbum: Shell Combinators http://plumbum.readthedocs.org

FAQs

Resources

  • Awesome Shell: A curated list of awesome command-line frameworks, toolkits, guides and gizmos. Inspired by awesome-php.
  • Awesome Bash: A curated list of delightful Bash scripts and resources.
  • awesome-cli-apps A curated list of command line apps
⚠️ **GitHub.com Fallback** ⚠️