Bash: 入门重点

Command List

(Not work in windows dos)

  • Enter

bash
  • Exit

exit
  • Current dir: get current folder path

pwd
currentPath=$PWD
> /d/Workspace/github/blog
  • Get parent path

dirname $PWD
> /d/Workspace/github
  • Get parent folder name

basename $PWD
> blog
  • Get all files/folders in current folder

dir
> dos-netstat-80.bat  git-global-user.sh  git-registry-taobao.sh  package.json
> git-commit.sh       git-local-user.sh   git-remote-template.sh  README.md
> git-commit-push.sh  git-pull-rebase.sh  LICENSE                 yx-env.iml
  • Get all files/folders, folder has last slash /

  • Get parent folder

  • Get parent's parent folder

  • Iterate folder's files and sub-folder

  • Stop exit with flash when exec to the end of bash

  • Multi-Line string variable

  • Get value from output string

Questions

  • unary operator expected: 表达式左边有可能为空,则表达式左侧就为空,报错

  • unary operator expected: 判断不等,加上双中括号

  • unary operator expected: 判断空,用双中括号和单等号

Error: TODO: 待解决

  • code ELIFECYCLE errno 1 (Mac 上直接执行 git-push.sh 时出现)

  • ChildProcess.exithandler (Mac 上通过child_process exec 执行 git-push.sh 时出现)

最后更新于

这有帮助吗?