Skip to content

Shell Note

Content of this should be considered always under zsh, unless otherwise specified.

coding first bash to convert obsidian notes#

glob filename pattern match#

  • @2021-11-26
  • objective is to delete all folder/files expect those under folder res/ (background: MkDocs needs the resources all under doc_dir)
  • This is called glob or globbing in tldp and Wiki: glob. Here are some examples
  • ! not working in zsh, use ^ instead: [!] (exclamation mark in brackets) wildcard in bash
  • man find shows that the regex seems bounded with ^ and $.
  • Running a executable file in Mac 12.0 will actually use sh, checked with ps -p $$

Mac flavor zsh#

  • @2021-11-28
  • zsh is not shell. When executing read -q , shell will throw an error while zshell has a builtin flag to read only one key and parse to "y" or "n"
  • to check builtin functions like which, we can use

    shell unalias run-help autoload run-help bindkey "^[h" run-help # input `type «Alt-h»' to run-help on type, but it's

TCC protection#

  • (@2021-11-28) Mac zsh has a special constraint shown as Can't open input file: zsh

    In macOS Transparency Consent and Control (TCC) restricts access to "personal" data, including anything in a user's Desktop folder and outputs a /bin/zsh: can't open input file error message if you try to disobey this rule. Try moving file-name.zsh to a different folder.

  • (@2021-11-28) The exact TCC protected folders are listed here MacOS Catalina launchd can't open input file error

    These specific folders are TCC protected in Catalina: ~/Desktop, ~/Documents, ~/Downloads, iCloud Drive, third-party cloud storage, if used, removable volumes, network volumes.

  • (@2021-12-01) The TCC will not block source some-script.zsh nor these files(also .sh, .bash) to run directly.

functions#

  • @2021-12-01
  • calling a function requires none () in mac terminal, but in VSCode terminal on Mac, the () is accepted.
  • failing will be silent by default.
    • [ ] how to change this? Test: Use set -o errexit to make it throw error. set -o pipefail to make it throw error if any command in pipe fails. also test setopt ERR_EXIT (setopt ERR_EXIT=true) (suggested by Copilot)

shell package managing system#

  • @2021-12-04
  • AKA Package Tool
  • Advanced Packaging Tool
  • On Mac, brew, pkgutil are also used.

Permission to execute#

  • @2021-12-15
  • chmod +x ${FILE_NAME}

Command line calculator#

  • @2021-12-15
  • bc is "An arbitrary precision calculator language"
  • Short guide
  • @2021-12
1
ln -s /path/to/original /path/to/link

current directory#