一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

Unix shell basics

 ihacku 2015-05-30

Unix shell basics

By David R?thlisberger. Comments welcome at david@.

Last updated 4 Oct 2012. These notes are placed in the public domain.

Rough notes for a half-hour course on Unix shell basics.

Run a program (ls)

  • ls
  • which ls
  • /bin/ls
  • cd /bin
  • ./ls
  • echo $PATH
  • cd -

Shell variables

  • echo PATH
  • echo $PATH
  • PATH=~
  • echo $PATH
  • ls (!)
  • put PATH back to original value

Manuals

  • man ls
  • man uses an external PAGER program, by default "less"
    • less keys (similar to vi):
      • h help
      • q quit
      • SPACE scroll forward
      • / search
      • n next search hit
    • less ../stb-tester/stbt.py
    • cat ../stb-tester/stbt.py
    • PAGER=cat man ls
  • shell builtins: man cd
    • also: help cd
  • man man
    • man passwd
    • man 5 passwd
    • man printf
    • man 3 printf
    • "ls(1)" means the ls manpage in section 1
  • man hier for a somewhat old-fashioned description of the file-system hierarchy

arguments

  • cat printargs.c

      #include <stdio.h>
    
      int main(int argc, char** argv) {
          int i;
          for (i = 0; i < argc; ++i) {
              printf("--- arg %d: ---\n", i);
              printf("%s\n", argv[i]);
          }
          return 0;
      }
    
  • gcc printargs.c -o printargs
  • ./printargs hello world

expansion

environment variables

  • cat printenv.c

      #include <unistd.h>
      #include <stdio.h>
    
      extern char** environ;
    
      int main(int argc, char** argv) {
          char** env;
          for (env = environ; *env; ++env) {
              printf("%s\n", *env);
          }
          return 0;
      }
    
  • gcc printenv.c -o printenv
  • ./printenv
  • STBT_CONFIG_FILE=~/.config/stbt/stbt.conf
  • ./printenv
  • STBT_CONFIG_FILE=~/.config/stbt/stbt.conf ./printenv
  • ./printenv
  • export STBT_CONFIG_FILE=~/.config/stbt/stbt.conf
  • ./printenv
  • env - A=1 B=2 ./printenv

standard input, output & error

  • Standard Input is where input data comes from, often the keyboard.
  • Standard Output is where output data goes, often the terminal screen.
  • grep o and type "hello" (RETURN) and "there" (RETURN) (on standard input)
  • Redirections
  • Standard error
    • grep < printenv.c > main.txt You wouldn't want the error going into main.txt
    • Not just for errors:
      • curl http://www.google.com
      • curl http://www.google.com > google.html
  • Pipelines

job control

  • http://www./software/bash/manual/html_node/Job-Control.html
  • sleep 600 press Control-C
  • sleep 600 press Control-Z
  • jobs Stopped
  • bg %1
  • jobs Running
  • man bash page down a bit, then press Control-Z
  • jobs
  • fg then press Control-Z again
  • sleep 700 &
  • jobs
  • kill %3 Same as sending Control-C to a foreground process
  • ps f
  • kill 1234 Give the process id of the sleep process instead of "1234"

exit code

  • Just an arbitrary number to communicate exit status to the calling process
  • ./printargs
  • echo $?
  • Modify printargs's main function to return 42
  • gcc printargs.c -o printargs
  • ./printargs
  • echo $?
  • The shell considers a 0 exit code as success, anything else as failure.
  • Also used by shell looping & conditional constructs:
    • if ./printargs; then echo ok; else echo failed; fi
    • ./printargs && echo ok Short-circuiting boolean AND
  • man grep Scroll down to EXIT STATUS near the end

Further reading

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多

    国产三级视频不卡在线观看| 人妻中文一区二区三区 | 国产日韩欧美一区二区| 免费观看一级欧美大片| 中文字幕一区二区三区大片| 亚洲国产成人av毛片国产| 欧美午夜国产在线观看| 亚洲午夜av一区二区| 日韩欧美国产精品自拍| 亚洲国产成人久久99精品| 好吊色免费在线观看视频| 国产精品午夜性色视频| 日本欧美一区二区三区高清| 成人午夜免费观看视频| 亚洲精品国产第一区二区多人| 国产精品视频第一第二区| 日韩精品在线观看一区| 中国一区二区三区人妻| 欧美日韩精品视频在线| 人妻熟女中文字幕在线| 日韩在线精品视频观看| 亚洲做性视频在线播放| 青青操日老女人的穴穴| 91插插插外国一区二区| 日本加勒比系列在线播放| 亚洲中文字幕三区四区| 欧美成人精品一区二区久久| 欧美日韩高清不卡在线播放| 欧美一级内射一色桃子| 欧美日韩亚洲综合国产人| 成年人免费看国产视频| 欧美一区二区三区五月婷婷| 东京热男人的天堂一二三区| 九九蜜桃视频香蕉视频| 中国少妇精品偷拍视频| 国产精品一区二区视频成人| 成人精品网一区二区三区| 内用黄老外示儒术出处| 欧美亚洲综合另类色妞| 亚洲精品国产精品日韩| 少妇人妻一级片一区二区三区|