EXEC command in Shell

Source: Internet
Author: User

1. Find in the -exec Parameters

in the current directory ( including subdirectories ), find all txt files and find the string "Bin" containing the the line

Find./-name "*.txt"-exec grep "bin" {} \;

in the current directory ( including subdirectories ), delete all txt file

Find./-name "*.txt"-exec rm {} \;

Execute command;  True if 0 status is returned. All following arguments to find was taken to being arguments to the command until a argument consisting of '; ' Is Encount  Ered. The string ' {} ' is replaced by the current file name being processed everywhere it occurs in the arguments to the Comman D, not just in arguments where it is alone.

2. Shell 's built-in command commands exec

#!/bin/ksh

Export Log=/tmp/test.log

EXEC >> $LOG 2>&1

Ls-l Kevin.txt

Exit 0

exec [ARG]

If Arg is present, executes ARG in place of the this shell.

(Arg would replace this shell).

Shell built-in commands exec will not start the new Shell, but instead use the command to be executed to replace the current Shell process, and to clean up the old process environment, and Other commands after the EXEC command will no longer execute.

So, if you're in aShellinside, executeexec lsthen, when the current directory is listed, theShellI quit because of this.Shellthe process has been replaced by just executinglscommand of a process, the execution of the end of nature will quit. To prevent this from affecting our use, we will generallyexeccommand to put in aShellinside the script, the script is called with the main script, which can be used at the call pointBash a.sh, (a.shis the script that holds the command), this willa.shCreate aSub Shellgo to execution, when executed toexec, the sub-script process is replaced with the correspondingexec's command.

Source command or " . ", no new for scripts Shell , but only the commands contained in the script are in the current Shell execution.

However, it is important to note an exception when The exec command does not replace the shell when it operates on the file descriptor , and after the operation is complete, the following commands continue to be executed.

exec 3<&0: This command is the operator 3 also points to standard input.

Original

[1]http://blog.chinaunix.net/uid-20652643-id-1906436.html

[2]http://zhgw01.blog.163.com/blog/static/1041481220098944425489/

[3]http://blog.csdn.net/clozxy/article/details/5818465

[4]http://www.cnblogs.com/zhaoyl/archive/2012/07/07/2580749.html

EXEC command in Shell

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.