1 / 36

Windows Batch VS Linux Shell

Windows Batch VS Linux Shell. Jason Zhu. Agenda. System and Shell Windows batch and Linux Shell Dos and Linux Shell internal Commands Windows and Linux external commands Batch and Shell variable and special sign Batch and Shell Key words

dyanne
Download Presentation

Windows Batch VS Linux Shell

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Windows Batch VS Linux Shell Jason Zhu

  2. Agenda • System and Shell • Windows batch and Linux Shell • Dos and Linux Shell internal Commands • Windows and Linux external commands • Batch and Shell variable and special sign • Batch and Shell Key words • build forge VS batch/shell • Batch/Shell VS Perl/python

  3. System history

  4. Shell history • Shell: a piece of software that provides an interface for users • Unix/Linux: Bourne/Korn/C/Tc/Bash • Linux GUI: Gnome,kde,xfce • Windows: cmd.exe/explorer.exe • http://en.wikipedia.org/wiki/Shell_(computing)

  5. The difference of Windows and Linux • Case sensitive in Linux • / in Linux • No relationship between executable file and extension • don't search current path • Security policy is more strict in Linux • link file VS shortcut • http://en.wikipedia.org/wiki/Comparison_of_Windows_and_Linux

  6. Same internal commands

  7. Different internal commands

  8. Other internal Commands

  9. Command help

  10. External commands

  11. Where to get more useful tools • http://unxutils.sourceforge.net/ • ftp://ftp.microsoft.com/reskit/ • http://www.microsoft.com/mspress/windowsserver2003reskit/ • http://live.sysinternals.com/ • http://www.nirsoft.net • Other such as zip/unzip…

  12. Robocopy(windows) • windows copy/xcopy: • copy “c:\new folder\1.txt” c: • copy “c:\new folder\1.txt” c:\2.txt • Linux cp/windows cp.exe • cp ~/a.txt ~/test (cp c:\1.txt c:\test2) • cp ~/a.txt ~/test/b.txt (cp c:\1.txt c:\3.txt) • Windows robocopy: • robocopy /E /NP /R:12 /w:10 /MIR SourceDirDestinationDir *.txt *.doc /XF test.txt /xd test • Must check the return value

  13. Printf(windows/Linux) • Printf • Printf %3d 2 • printf %-3d 2 • Printf %03d 2 • Printf %1.2f 3.1415926 • printf %8s "aaaa" • printf "\nSubDoc: %03d\n" 3

  14. Expr(windows/Linux) • expr 5 + 7 expr 5 – 6 • expr 5 ”*” 4 expr 5 / 7 • expr 7 % 9 • expr 1 “|”   0 expr 1 “&” 0 • expr 3 “>” 6 expr 3 “<” 6 • expr 3 “>=” 3 expr 3 “<=” 3 • expr 3 = 3 expr 3 != 3 • exprexpr1 :re expr index expr1expr2 • exprsubstrexpr1expr2expr3 • expr length "abcdef" • expr length "abcdef" "<" 5 "|" 15 - 4 ">" 8

  15. Awk(windows/Linux) • awk '{print $0}' scores.txt • awk '{if($2 ^> "60") print $0}' scores.txt • awk 'BEGIN {print "start..."} {tot+=$2} END {print "totoal is:" tot; print "END..."}' scores.txt • awk '{print length($2)}' scores.txt

  16. sed • sed [选项] s e d命令 输入文件。 • sed = test3.txt • sed s/mapguide/mapguide2010/g test3.txt • sed 5,6d test3.txt • sed 3a\abcd test3.txt • sed 10i\adflajflad\n\adfadfajdlf test3.txt • Sed 10c\aaaa test3.txt • sed 4q test3.txt • sed 2r 1.txt test3.txt

  17. grep • grep "map" test4.txt • grep "map" *.txt • grep -c “aud“ test4.txt • grep -n “aud“ test4.txt • grep -v “aud“ test4.txt • grep -i “aud“ test4.txt

  18. Batch VS Shell

  19. Environment variables

  20. Environment variables shift

  21. Environment variables

  22. Linux 参数变量 • a. 变量=${参数-word}:如果设置了参数,则用参数的值置换变量的值,否则用word置换。即这种变量的值等于某一个参数的值,如果该参数没有设置,则变量就等于word的值。 • b. 变量=${参数=word}:如果设置了参数,则用参数的值置换变量的值,否则把变量设置成word,然后再用word替换参数的值。注意,位置参数不能用于这种方式,因为在Shell程序中不能为位置参数赋值。 • c. 变量=${参数?word}:如果设置了参数,则用参数的值置换变量的值,否则就显示word并从Shell中退出,如果省略了word,则显示标准信息。这种变量要求一定等于某一个参数的值。如果该参数没有设置,就显示一个信息,然后退出,因此这种方式常用于出错指示。 • d. 变量=${参数+word}:如果设置了参数,则用word置换变量,否则不进行置换。

  23. Call/start/source/sh

  24. Special signs

  25. Expression caculation

  26. Error status

  27. 变量延迟 If/then/else

  28. Label/goto/function

  29. For

  30. Linux- Until/while/case/break/continue • while CONTROL-COMMAND; do CONSEQUENT-COMMANDS; done • until TEST-COMMAND; do CONSEQUENT-COMMANDS; done • case EXPRESSION in CASE1) COMMAND-LIST;; CASE2) COMMAND-LIST;; ... CASEN) COMMAND-LIST;; esac • select WORD [in LIST]; do RESPECTIVE-COMMANDS; done • Break/continue

  31. Build Forge vs batch and shell • variables definition : build forge syntax • Variables using: both of windows and Linux • Slashes: both of them are ok • For linux OS: shell syntax • For Windows OS: batch syntax

  32. Batch and shell VS perl and python • Shell simply and suitable for daily work • Perl/python can work in different os; more powerful; but complex;

  33. Shell and batch references • http://technet.microsoft.com/zh-cn/library/cc758944(WS.10).aspx • http://www.arachnoid.com/linux/shell_programming.html • http://www.freeos.com/guides/lsst/ • http://linuxcommand.org/

  34. Batch and shell books • Microsoft Windows Shell Script Programming for the Absolute Beginner.chm • 批处理阶段教程奥运最终版[英雄出品] • Bash.新手指南.中文版.(Bash.Beginners.Guide.CHS).CHM • Learning the bash Shell, 3rd Edition.chm • UNIX Shells by Example Fourth Edition.chm

  35. Q&A • Thanks

  36. Interactive Input

More Related