Windows Batch VS Linux Shell. Jason Zhu

Similar documents
如何查看 Cache Engine 缓存中有哪些网站 /URL

PCU50 的整盘备份. 本文只针对操作系统为 Windows XP 版本的 PCU50 PCU50 启动硬件自检完后, 出现下面文字时, 按向下光标键 光标条停在 SINUMERIK 下方的空白处, 如下图, 按回车键 PCU50 会进入到服务画面, 如下图

ICP Enablon User Manual Factory ICP Enablon 用户手册 工厂 Version th Jul 2012 版本 年 7 月 16 日. Content 内容

Previous on Computer Networks Class 18. ICMP: Internet Control Message Protocol IP Protocol Actually a IP packet

Command Dictionary CUSTOM

AvalonMiner Raspberry Pi Configuration Guide. AvalonMiner 树莓派配置教程 AvalonMiner Raspberry Pi Configuration Guide

Understanding IO patterns of SSDs

Logitech G302 Daedalus Prime Setup Guide 设置指南

nbns-list netbios-type network next-server option reset dhcp server conflict 1-34

计算机组成原理第二讲 第二章 : 运算方法和运算器 数据与文字的表示方法 (1) 整数的表示方法. 授课老师 : 王浩宇

Triangle - Delaunay Triangulator

SNMP Web Manager. User s Manual

实验三十三 DEIGRP 的配置 一 实验目的 二 应用环境 三 实验设备 四 实验拓扑 五 实验要求 六 实验步骤 1. 掌握 DEIGRP 的配置方法 2. 理解 DEIGRP 协议的工作过程

三 依赖注入 (dependency injection) 的学习

<properties> <jdk.version>1.8</jdk.version> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties>

Chapter 1 (Part 2) Introduction to Operating System

NetScreen 概念与范例. ScreenOS 参考指南 第 7 卷 : 虚拟系统. ScreenOS 编号 SC 修订本 E

Chapter 11 SHANDONG UNIVERSITY 1

Chapter 7: Deadlocks. Operating System Concepts 9 th Edition

上汽通用汽车供应商门户网站项目 (SGMSP) User Guide 用户手册 上汽通用汽车有限公司 2014 上汽通用汽车有限公司未经授权, 不得以任何形式使用本文档所包括的任何部分

测试 SFTP 的 问题在归档配置页的 MediaSense

学习沉淀成长分享 EIGRP. 红茶三杯 ( 朱 SIR) 微博 : Latest update:

组播路由 - MSDP 和 PIM 通过走

Apache Kafka 源码编译 Spark 大数据博客 -

Command Dictionary -- DAMSTAB

OTAD Application Note

display portal server display portal user display portal user count display portal web-server

Operating Systems. Chapter 4 Threads. Lei Duan

Skill-building Courses Business Analysis Lesson 3 Problem Solving

Microsoft RemoteFX: USB 和设备重定向 姓名 : 张天民 职务 : 高级讲师 公司 : 东方瑞通 ( 北京 ) 咨询服务有限公司

mod_callcenter callcenter.conf.xml 范例 odbc-dsn

Air Speaker. Getting started with Logitech UE Air Speaker. 快速入门罗技 UE Air Speaker. Wireless speaker with AirPlay. 无线音箱 (AirPlay 技术 )

Supplementary Materials on Semaphores

Software Engineering. Zheng Li( 李征 ) Jing Wan( 万静 )

ROOT Analysis FrameWork (II) Basics. Qipeng Hu March 22, 2015

PTZ PRO 2. Setup Guide 设置指南

Autodesk Backburner 2011 安装手册

Lecture 3 for pipelining

Multiprotocol Label Switching The future of IP Backbone Technology

OpenCascade 的曲面.

Packaging 10Apr2012 Rev V Specification MBXL HSG 1. PURPOSE 目的 2. APPLICABLE PRODUCT 适用范围

CA Application Performance Management

Bi-monthly report. Tianyi Luo

Sun XVR-300 图形加速器用户指南

TBarCode OCX Microsoft ActiveX compliant Barcode Control

ZWO 相机固件升级参考手册. ZWO Camera Firmware Upgrade reference manual. 版权所有 c 苏州市振旺光电有限公司 保留一切权利 非经本公司许可, 任何组织和个人不得擅自摘抄 复制本文档内容的部分或者全部, 并

漂亮的测试. By Alberto Savoia 代码之美 第七章 史际帆

菜鸟调错 原文出处 : 菜鸟调错作者 : 刘水镜 本系列文章经作者授权在看云整理发布, 未经作者允许, 请勿转载! 菜鸟调错 分享开发中遇到的各种各样的错误, 以及解决方法, 让更多的人少走同样的弯路 本文档使用看云构建

T19264B -1 SPECIFICATION FOR APPROVAL 产品说明书 T19264B-1( 带中文字库 ) APPOVED SIGNATURES Blue Moon Customer

A bottom-up parser traces a rightmost derivation in reverse. Bottom-Up Parsing. Bottom-up parsing is more general than topdown.

Safe Memory-Leak Fixing for C Programs

<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <!--- global properties --> <property>

Spark Standalone 模式应用程序开发 Spark 大数据博客 -

Chapter 2: Java OO II. Yang Wang wyang AT njnet.edu.cn

Grandstream Networks, Inc.

U-CONTROL UMX610/UMX490/UMX250. The Ultimate Studio in a Box: 61/49/25-Key USB/MIDI Controller Keyboard with Separate USB/Audio Interface

Additional Information

Decode Zend. Darkness/Airsupply

Color LaserJet Pro MFP M477 入门指南

第二小题 : 逻辑隔离 (10 分 ) OpenFlow Switch1 (PC-A/Netfpga) OpenFlow Switch2 (PC-B/Netfpga) ServerB PC-2. Switching Hub

Cisco IP Phone 8800 系列和 Cisco IP Conference Phone 8832 多平台 电话设置指南

MP3 文件是由帧 (frame) 构成的, 帧是 MP3 文件最小的组成单位 MP3 的全称应为 MPEG1 Layer-3 音频文件,MPEG(Moving Picture Experts Group) 在汉语中译为活动图像专家组, 特指活动影音压缩标准,MPEG

Technology: Anti-social Networking 科技 : 反社交网络

Lecture 3 Process API in UNIX systems

朱晔和你聊 Spring 系列 S1E2: SpringBoot 并不神秘

public static InetAddress getbyname(string host) public static InetAddress getlocalhost() public static InetAddress[] getallbyname(string host)

Logitech ConferenceCam CC3000e Camera 罗技 ConferenceCam CC3000e Camera Setup Guide 设置指南

RPG IV 新特性概览. 钟嘉田 DB2 for i Performance, IBM 中国系统与科技研发中心

Ganglia 是 UC Berkeley 发起的一个开源集群监视项目, 主要是用来监控系统性能, 如 :cpu mem 硬盘利用率, I/O 负载 网络流量情况等, 通过曲线很容易见到每个节点的工作状态, 对合理调整 分配系统资源, 提高系统整体性能起到重要作用

VAS 5054A FAQ ( 所有 5054A 整合, 中英对照 )

Useful Unix Commands Cheat Sheet

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

XML allows your content to be created in one workflow, at one cost, to reach all your readers XML 的优势 : 只需一次加工和投入, 到达所有读者的手中

密级 : 博士学位论文. 论文题目基于 ScratchPad Memory 的嵌入式系统优化研究

PubMed 简介. PubMed 是美国国立医学图书馆 (NLM) 所属的国家生物技术信息中心 (NCBI) 开发的因特网生物医学信息检索系统

CHINA VISA APPLICATION CONCIERGE SERVICE*

Declaration of Conformity STANDARD 100 by OEKO TEX

Epetra_Matrix. August 14, Department of Science and Engineering Computing School of Mathematics School Peking University

The relational Algebra & calculus cont. Reference : UC Berkeley

A Benchmark For Stroke Extraction of Chinese Characters

Wireless Presentation Pod

SHANDONG UNIVERSITY 1

1. DWR 1.1 DWR 基础 概念 使用使用 DWR 的步骤. 1 什么是 DWR? Direct Web Remote, 直接 Web 远程 是一个 Ajax 的框架

TW5.0 如何使用 SSL 认证. 先使用 openssl 工具 1 生成 CA 私钥和自签名根证书 (1) 生成 CA 私钥 openssl genrsa -out ca-key.pem 1024

[CVE ] GNU binutils Integer Overflow

最短路径算法 Dijkstra 一 图的邻接表存储结构及实现 ( 回顾 ) 1. 头文件 graph.h. // Graph.h: interface for the Graph class. #if!defined(afx_graph_h C891E2F0_794B_4ADD_8772_55BA3

CloudStack 4.3 API 开发指南!

Oriented Scene Text Detection Revisited. Xiang Bai Huazhong University of Science and Technology

Chapter2 Instruction Sets

搭建最简单的 SpringMVC 框架 ( 使用 maven)

Python for Everybody. Exploring Data Using Python. Charles R. Severance

IPC 的 Proxy-Stub 设计模式 (b)

Virtual Memory Management for Main-Memory KV Database Using Solid State Disk *

MateCam X1 User Manual

Oxford isolution. 下載及安裝指南 Download and Installation Guide

Stratix V 器件中的收发器配置. Stratix V 器件含有一个专用的收发器物理编码子层 (PCS) 和物理介质附加子层 (PMA) 电路 要实现一个协议, 请使用表 4-1 中所列出的 PHY IP

: Operating System 计算机原理与设计

Protocol in General Outline. What is protocol. Why using protocol. What kind of Protocols are there.

Apache OpenWhisk + Kubernetes:

Transcription:

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 build forge VS batch/shell Batch/Shell VS Perl/python

System history

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_(computin g)

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_wi ndows_and_linux

Same internal commands MS-DOS /Linux / Unix description echo set date time cd more exit pushd popd Displays messages. Displays environment variables. Displays or sets the date. Displays or sets the system time. Displays the name of the current directory. Display the content in several pages Exit dos or shell external. Saves the current directory then changes it. Restores the previous value of the current directory saved by pushd.

Different internal commands MS-DOS Linux / Unix descriptions cls clear Clears the screen. dir ls Displays a list of files and subdirectories in a directory. type cat Displays the contents of a text file. attrib chmod Displays or changes file attributes. copy / xcopy del /rd /erase move /ren / rename cp rm mv Copies one or more files to another location. Deletes one or more files. md /mkdir mkdir Creates a directory. Moves one or more files from one directory to another directory. cd pwd Displays the name of the current directory. find /findstr(stri ng in file) find (file) Searches for a text string in a file or files. Searches for a file in a directory.

Other internal Commands MS-DOS Linux / Unix descriptions at Schedules commands and programs to run on a computer. comp / fc ver / cmd tree subst assoc Compares the contents of two files or sets of files. Displays the Windows version. Graphically displays the directory structure of a drive or path. Associates a path with a drive letter. Displays or modifies file extension associations. chmod chown Change access permissions Change file owner and group tasklist ps Process status task kill kill Stop a process from running who whoami Print all usernames currently logged in Print the current user id and name

Command help MS-DOS help help command-name Linux / Unix help command-name -help Command-name /? whatis command-name whereis command-name man command-name Info command-name type command-name http://www.computerhope.com http://www.ss64.com http://www.robvanderwoude.com

External commands Windows Linux / Unix description ping ping Test internet connection. shutdown shutdown Turn off or reboot the machine. sleep sleep Delay for a specified time ipconfig ifconfig Displays or changes internet information. Zip/unzip/ gzip/7zip robocopy Compress or uncompress files. Copy files or directory robustly. printf printf Format and print data. expr expr Evaluate expressions sed sed Stream editor for filtering and transforming text. (replace and delete) awk awk AWK is a programming language that is designed for processing text-based data, either in files or data streams. grep grep Print lines matching a pattern.

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

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 SourceDir DestinationDir *.txt *.doc /XF test.txt /xd test Must check the return value

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

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 expr expr1 : re expr index expr1 expr2 expr substr expr1 expr2 expr3 expr length "abcdef" expr length "abcdef" "<" 5 " " 15-4 ">" 8

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

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

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

Batch VS Shell Windows.bat /.cmd Linux/Unix.sh /.ksh /.bash /.csh/.tcsh #!/bin/sh @echo off Bash x filename.sh Rem (::) # chmod a+x filename filename./filename

Environment variables Windows Set Name = Value Set path = Name;%PATH% Echo %path% set ; : %Name% Linux/Unix Name=Value PATH=Name:$PATH Echo $PATH No spaces Case Sensitive $Name readonly

windows Environment variables linux %* $* Lists all the arguments that have been passed to the script %0 $0 Stores the name of the script %1~9 $1~9 Stores the first to ninth argument passed to the script $# The number of arguments $$ The current process id $! The last background process id If parameters include blank spaces, you would need to surround both file names with double quotes before passing them to your script shift

Environment variables windows linux replace %VariableName:ReplacementString=Origin alstring% set a=belcome to CMD borld! set temp=%a:b=w% echo %temp% pause 将显示 welcome to CMD world! 即用 w 替换了变量 a 中的 b ${VAR/PATTERN/STRING} or ${VAR//PATTERN/STRING} 语法 第一种形式仅仅替换第一个匹配的项目, 第二个用 STRING 替换所有匹配 PATTERN 的项目 substr %VariableName:~StartPosition,Length% set a=superhero set temp=%a:~0,-3% echo %temp% pause 将显示 superh 即显示了变量 a 的第 0 位和第 -3 位中间包含的所有字符 ${varname:offset:length} Purpose: Returning parts of a string (substrings or slices). STRING="thisisaverylongn ame" echo ${STRING:6:5}

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

Call/start/source/sh Widnwos call Start Setlocal/endlocal Linux Source (sh 中可以使用 dot command 即.shell file name) Sh filename (sh filename &) Export

Windo ws linux & & command1 & command2 Special signs Runs the first command followed by the second command Comand1 command2 The result of the first comand will be as input of the second command && && command && command Runs the second command if the first command was successful command command Runs the second command if the first command had an error > > Echo hello > file.txt Transfer and overwrite >> >> Type file1.txt >> file.txt Transfer and append < < command < command ^ \ Disable the meaning of some special signs, such as >,<,& :: # Comment, it is equal to REM

Expression caculation windows SET /A variable = Expression set /a var=5+2 set /a var=55*34 set /a var=55/34 set /a var=55%%34 set /a var= (8+(9/3+7))*3 但 set /a vat=55.1*34 是错误的, 因为批处理不支持浮点运算 SET /A x = 1 SET /A y = 2 SET /A z = x + y + 3 ECHO z a=2 c=5 let b=$a*$c echo $b $((i++)) $((3 > 2)) $(( (3 > 2) (4 <= 1) )) declare -i val3=12 val4=5 declare -i result2 result2=val3*val4 echo $result2

Error status windows Linux errorlevel $? 2> file :Sends all error output to a file or device 2>&1 :Sends all error output to the same location as all normal output 文件描述符通常是 :STDIN,STDOUT,STDERR, 即 :0,1,2, 由此可以看出, 它将 command 在输出过程中产生的错误信息也放在了 STDOUT Standard Input. The location where the Windows shell looks for command input. By default, this is the computer's keyboard. Standard Output. The default location where the Windows shell sends all output. By default, this is the Windows command console. Standard Error. The default location where the Windows shell sends all error messages. By default, this is the Windows command console.

If/then/else 变量延迟 windows IF [NOT] EXIST filename command IF EXIST filename. ( del filename. ) ELSE ( echo filename. missing. ) if TEST-COMMANDS; then CONSEQUENT-COMMANDS; fi 如果 TEST-COMMANDS 结果是 0, 则执行 then 中的语句 if TEST-COMMANDS; then CONSEQUENT-COMMANDS; elif MORE-TEST-COMMANDS; then MORE-CONSEQUENT-COMMANDS; else ALTERNATE-CONSEQUENT- COMMANDS; fi

Label/goto/function Windows batch @echo off echo 调用前 echo 调用子过程 call :sub Linux shell function FUNCTION { COMMANDS; } 或者 FUNCTION () { COMMANDS; } 调用 FUNCTION arguments echo 调用后 Goto end :sub echo 子过程调用中 goto :eof :end echo 退出 Pause exit

For FOR %variable IN (set) DO command [commandparameters] 在批处理程序中使用 FOR 命令时, 指定变量请使用 %%variable 而不要用 %variable 变量名称是区分大小写的, 所以 %i 不同于 %I. /l Sets up the loop to process a range of values /f Sets up the loop to process all elements stored within a string /d Sets up the loop to process all files stored within a specified folder /r Sets up the loop to process all subfolders stored within a specified parent folder for %%i in (a b c d e f g h i ) do ( echo %%i ) for /l %%i in (1,1,100) do ( set /a var+=1 ) for NAME [in LIST ]; do COMMANDS; done

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

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

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;

Shell and batch references http://technet.microsoft.com/zhcn/library/cc758944(ws.10).aspx http://www.arachnoid.com/linux/shell_progra mming.html http://www.freeos.com/guides/lsst/ http://linuxcommand.org/

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

Thanks Q&A

Interactive Input windows SET /P Var=[MessagePrompt] @echo off set /p input= 请输入! echo 您输入的是 %input% pause Read -p PROMPT name read year p input: Echo 您输入的是 $year