命令操作符
1.
元字符
在命令行中有特殊含義的一些字符,通過這些字符表示一些特殊含義,稱為元字符。它們包括:
(1)
??????
分隔符:包括空白、分號
(;)
、逗號
(,)
和雙引號
分號和逗號分割參數和命令,如果命令和參數之間的用它們連接則默認第一個參數為空。但是他們都會包含在
%*
中
(2)
??????
環境變量的引用符號:
百分號
(%)
(3)
??????
管道,重定向符,命令分隔符:
|? &? ^
(
escape
)
? <? >
2.
如何重定向命令輸入和輸出?
在
MS-DOS
下每個進程可以打開
10
個文件,其中有一些是默認的,這些文件用句柄來操作:
文件句柄是
0~9
的整數。可以通過輸出和輸入重定向改變對文件的讀
/
寫操作。文件句柄可以看作操縱文件的指針。重定向則是對這些指針重新賦值,使其志祥所指定的文件。
?
重定向操作符一共有五種:
|
輸出重定向,可以是文件名,空設備
nul,
打印機
prn,
該操作符左端默認的文件句柄是
1
|
|
|
|
|
|
輸出重定向到另外一個文件句柄,該操作符左端默認的文件句柄是
1
|
|
輸入重定向到另外一個文件句柄,該操作符左端默認的文件句柄是
0
|
|
|
?
重定向命令按照在命令行中的順序進行,例如:
<command> >> <log-file>? 2>&1
上述命令首先將標準輸出重定向到
<log-file>
,然后將其復制到標準錯誤輸出。上述命令中的順序不能改變。
?
另外,重定向的操作是單向的,即對讀寫操作是分開的:
<command> 3><output-file>
上述命令僅將對文件句柄
3
的輸出定向到
<output-file>
并不影響從文件句柄讀取原來的輸入。
3.
如何理解管道?
管道命令的格式如下:
一句話,該命令將
<command1>
的標準輸出重定向至管道,將
<command2>
的標準輸入重定向至管道。
4.
如何定義復合語句?
復合語句由一些命令操作符來連接:
|
|
|
|
<Command1>
?&& <Command2>
|
只有當第一個命令執行成功后才執行第二個命令(由命令的錯誤代碼決定)
|
|
<Command1>
?||?<Command2>
|
只有當第一個命令執行失敗后才執行第二個命令(由命令的錯誤代碼大于
0
決定)
|
|
( <
Command1>
?&?<Command2>)
|
|
|
<Command1>
?<Parameter1>;<Parameter2>
|
|
5.
命令通配符
(一些命令中某些區域)
在有些命令的某些區域,可以使用通配符
(wildcard),
通配符有兩個:
?
–
匹配任意一個字符
*
–
匹配任意多個字符
實用命令
(in updating)
Sort
Find
more
環境變量
1.
???
環境變量如何初始化?
命令解釋器某一運行時刻的環境變量的來源和初始化依次如下建立:
-
?????????
命令解釋器內置變量
-
?????????
系統變量(在
HKEY_LOCAL_MACHINE
下定義)系統管理員設定
-
?????????
本地變量(在
HKEY_CURRENT_USER
下定義)用戶指定
-
?????????
Autoexec.bat
定義的變量
-
?????????
登陸腳本定義的變量
-
?????????
用戶交互命令定義的變量
?
?
2.
?
常用環境變量
?
|
|
Returns the location of the All Users Profile.
|
|
|
Returns the location where applications store data by default.
|
|
|
Returns the current directory string.
|
|
|
Returns the exact command line used to start the current Cmd.exe.
|
|
|
Returns the version number of the current Command Processor Extensions.
|
|
|
Returns the name of the computer.
|
|
|
Returns the exact path to the command shell executable.
|
|
|
Returns the current date. Uses the same format as the date /t command.
|
|
|
Returns the error code of the most recently used command. A non zero value usually indicates an error.
|
|
|
Returns which local workstation drive letter is connected to the user's home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
|
|
|
Returns the full path of the user's home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
|
|
|
Returns the network path to the user's shared home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
|
|
|
Returns the name of the domain controller that validated the current logon session.
|
|
|
Specifies the number of processors installed on the computer.
|
|
|
Returns the operating system name. Windows?2000 displays the operating system as Windows_NT.
|
|
|
Specifies the search path for executable files.
|
|
|
Returns a list of the file extensions that the operating system considers to be executable.
|
|
|
Returns the chip architecture of the processor. Values:
x86
or IA64 (
Itanium
–based).
|
|
|
Returns a description of the processor.
|
|
|
Returns the model number of the processor installed on the computer.
|
|
|
Returns the revision number of the processor.
|
|
|
Returns the command prompt settings for the current interpreter. Generated by Cmd.exe.
|
|
|
Returns a random decimal number between 0 and 32767. Generated by Cmd.exe.
|
|
|
Returns the drive containing the Windows server operating system root directory (that is, the system root).
|
|
|
Returns the location of the Windows server operating system root directory.
|
|
|
Returns the default temporary directories that are used by applications available to users who are currently logged on. Some applications require TEMP and others require TMP.
|
|
|
Returns the current time. Uses the same format as the time /t command.
|
|
|
Returns the name of the domain that contains the user's account.
|
|
|
Returns the name of the user who is currently logged on.
|
|
|
Returns the location of the profile for the current user.
|
|
|
Returns the location of the operating system directory.
|
?
3.
如何設置包括特殊字符的環境變量?
如果使用包含特殊字符
<, >, |, &, or ^,
的環境變量,則需要在前面加上轉義字符
^
,該字符即使在引號中也有效果。
如果定義含有引號的環境變量,則引號也是變量值的一部分。
環境變量的定義到行尾,不包括行尾空白。