Common commands-input and output, execution status

Source: Internet
Author: User
Tags control characters

Input/Output

Standard input: The default is the keyboard and can be specified as a file.

Standard output: The default is the screen and can be specified as a file.

If a line cannot end at terminal input, you can use the backslash \ on the next line to enter it.

Echo

echo is used to output a string
1 when using a double-quoted string, the internal $ variable will be replaced, the internal anti-single-quote command will output ' ', but the escape character will not escape.
2 using single-quote strings, the $ variable is not replaced, the return quotation marks do not execute the command, and the escape character escape does not occur.
3 do not use quotation marks equal to use double quotation marks.

ECHO has three control options:
-n Do not output the trailing newline
-e enable interpretation of backslash escapes
-e Disable interpretation of backslash escapes (default)

# No Line break after output Echo "  "read first_name# output after line echo""read last_name# No Output tab character echo"firstname\tlast name"# Output with tab character  echo"${first_name}\t${last_name}"
Read

Read is followed by the variable name, which reads the input stream until the newline or EOF (which can be passed ctrl+d).
1. If there are multiple variables, each read-in will be assigned to the variable by a blank character split.
2. If the number of partitions is many, the last variable gets all the input after that.

Usage
Read [-ers] [-a array] [-D delimiter] [-I buffer literal] [-n read characters] [-n read Characters] [-P prompt] [-t timeout] [-u file descriptor] [name ...]

Cat

Used to display file contents, control characters, line numbers, and so on.

If no file is specified, or if the file is "-", it is read from the standard input.

-A,--show-all equivalent To-vet
-B,--number-nonblank number nonempty output lines, overrides-n
-e equivalent To-ve
-E,--show-ends display $ at end
-N,--number number all output lines
-S,--squeeze-blank suppress repeated empty output lines
-T vs.-VT equivalence
-T,--show-tabs to display the ^i character as a
-U (ignored)
-V,--show-nonprinting uses ^ and M-references, except LFD and TAB

Pipe Pie

The pipeline can pass the output of one command to another command as input. For piping | Said. form for
Command 1 | Command 2

Read the contents of the file into a variable, as in the following command.

Cat Text.txt | Read Var
Tee

The standard input is output to the standard output. Also, copy to the appropriate file.

[Email protected] ~echotee  a.txtabcdefg[email protected]-254lbla ~   Cat  A.TXTABCDEFG

Tee has a-a option that represents appending to a file.

redirect

When you open the shell, each process has three open files associated with it, namely:

Standard input: Default is the keyboard file descriptor: 1
Standard output: Default is screen file descriptor: 2
Standard ERROR: Default is screen file descriptor: 3

If there are other files that require descriptors, you can use the 3-9 number arbitrarily.

How to redirect:

    1. > redirect standard output to a new file.
    2. >> redirects the standard output, which is appended to the file.
    3. < REDIRECT standard input.

Redirection in the form of:

    1. Output file descriptor > file name
    2. Output file descriptor > & Output File descriptor
    3. < Enter a file name
    4. < & Input File descriptor

Command > FileName

REDIRECT standard output to a new file

Command >> filename

REDIRECT standard output to a file (append)

Command 1 > Fielname

REDIRECT standard output to a file

Command > FileName 2>&1

REDIRECT standard output and standard error to a file

Command 2 > FileName

redirect standard errors to a file

Command 2 >> filename

REDIRECT standard output to a file (append)

Command >> filename 2>&1

REDIRECT standard output and standard error to a file (append)

Command < filename >filename2

The command command with the filename file as the standard input to the filename 2 file

As standard output

Command < filename

command commands with F i l e n a m e file as standard input

Command << delimiter

Read from the standard input until the delimiter delimiter is encountered

Command <&m

File descriptor m as standard input

Command >&m

redirect standard output to file descriptor M

Command <&-

Turn off the standard input

Execution status exec

EXEC cleans up the current shell environment, restarts a shell, and executes the commands that follow. After the command execution is complete, the shell closes. The new shell has the same PID as the original shell.

If the shell script file is executed purely and the first line of the file declares the shell path, start the child shell to execute the command in it
If the shell file is executed using the source command, the command in the current shell execution file.

Background execution commands

The commands associated with the background execution are:

    1. & at the end of the command, you can immediately put this line of command in the background execution. In order not to interfere, the output is usually redirected to a file, so that it does not appear on the screen.
    2. Nohup command, followed by the command line after the user exits and then continues to run in the background.
      Usually use Nohub Command &
    3. CTRL + Z: puts the currently executing command in the background and pauses execution.
    4. Jobs: View commands executed in the background
    5. FG%jobnumber: The background command numbered NUM is transferred to the foreground for execution.
    6. BG%jobnumber: Put tasks in the background to handle
    7. Kill%jobnumber: Kill background Task

Common commands-input and output, execution status

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.