&&
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.