Control method of execution order of shell command

Source: Internet
Author: User
Tags sort

&&
Command 1 && Command 2: If this command executes successfully && then execute this command.
[Development]/usr/xxxx/ytcclb>ls-l Test.sql
-rwxr--r--1 xxxx Group Nov 14:12 Test.sql
[Development]/USR/XXXX/YTCCLB>CP Test.sql Test.bak && echo "Coping file ok!"
Coping file ok!
[Development]/usr/xxxx/ytcclb>ls-l Test.*
-rwxr--r--1 xxxx Group Nov 17:48 Test.bak
-rwxr--r--1 xxxx Group Nov 14:12 Test.sql

Move files, delete directories:
$ mv/apps/bin/apps/dev/bin && rm-r/apps/bin
Sort files, output to another file, and print after success:
$ sort Test.sql > Test.bak && LP Test.bak

||
Command 1 | | Command 2: If this command fails to execute | | Then execute this command.
$ cp Test.sql Test.bak | | echo "Errors occured during coping file"
For example:
[Develop]/USR/XXXX/YTCCLB>CP Test.sql Test.bak
[Development]/usr/xxxx/ytcclb>ls-l Test.*
-rwxr--r--1 xxxx Group Nov 18:08 Test.bak
-rwxr--r--1 xxxx Group Nov 14:12 Test.sql
[Develop]/usr/xxxx/ytcclb>chmod u-w Test.bak
[Development]/usr/xxxx/ytcclb>ls-l Test.*
-r-xr--r--1 xxxx Group Nov 18:08 Test.bak
-rwxr--r--1 xxxx Group Nov 14:12 Test.sql
[Develop]/USR/XXXX/YTCCLB>CP Test.sql Test.bak | | echo "Errors occrued during coping file"
Cp:unable to create file Test.bak:Permission denied (Error 13)
Errors occrued during coping file
[Development]/usr/xxxx/ytcclb>

() and {}: Use a combination of several commands.
(Command 1; command 2; ...): Executes a set of commands in the current shell.
{command 1; command 2;.}: The contents of the curly braces are executed as a whole.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.