黑客与摇滚~~- -| 回首页 | 2005年索引 | - -揪出QQ宠物炫的真实地址

如何使用组合命令(Compound Command) - -

                                      

1、&
Usage:第一条命令 & 第二条命令 [& 第三条命令...]
用这种方法可以同时执行多条命令,而不管命令是否执行成功
Sample:
C:\>dir z: & dir c:\adam
The system cannot find the path specified.
 Volume in drive C has no label.
 Volume Serial Number is 0078-59FB
 Directory of c:\adam 
2002-05-14  23:51       

          .
2002-05-14  23:51                 ..
2002-05-14  23:51                   14 sometips.gif

2、&&
Usage:第一条命令 && 第二条命令 [&& 第三条命令...]
用这种方法可以同时执行多条命令,当碰到执行出错的命令后将不执行后面的命令,如果一直没有出错则一直执行完所有命令;
Sample:
C:\>dir z: && dir c:\adam
The system cannot find the path specified.
C:\>dir c:\adam && dir z:
 Volume in drive C has no label.
 Volume Serial Number is 0078-59FB
 Directory of c:\adam
2002-05-14  23:55                 .
2002-05-14  23:55                 ..
2002-05-14  23:55                   14 sometips.gif
               1 File(s)             14 bytes
               2 Dir(s)     768,671,744 bytes free
The system cannot find the path specified

在做备份的时候可能会用到这种命令会比较简单,如:
dir \\192.168.0.1\database\backup.mdb && copy \\192.168.0.1\database\backup.mdb E:\backup
如果远程服务器上存在backup.mdb文件,就执行copy命令,若不存在该文件则不执行copy命令。这种用法可以替换IF exist了 :)
3、||
Usage:第一条命令 || 第二条命令 [|| 第三条命令...]
用这种方法可以同时执行多条命令,当碰到执行正确的命令后将不执行后面的命令,如果没有出现正确的命令则一直执行完所有命令;
Sample:
C:\adam>dir sometips.gif || del sometips.gif
 Volume in drive C has no label.
 Volume Serial Number is 0078-59FB
 Directory of C:\adam
2002-05-14  23:55                   14 sometips.gif
               1 File(s)             14 bytes
               0 Dir(s)     768,696,320 bytes free

- 作者: 雾都孤狼 访问统计: 2005年06月19日, 星期日 12:29 加入博采

Trackback

你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=1978743

回复

评论内容: