Input and output in the shell (Bash Shell 03)

Source: Internet
Author: User

Input and output in the shell
Standard input: Keyboard
Standard output: Terminal display
The >> append is a newline append
Echo
- n do not trailing line breaks
-e enable escape function to interpret backslashes
-e disables the escape function that interprets backslashes (default)
--HELP Display this help message and exit
--version display version information and exit

Only with Cat
Figure 8
Cat<filename1>filename2

Inline input redirection
Command<<eof (identifier)
Data
EOF (identifier)

Redirecting input and output in scripts
Temporary redirection
Permanent redirection
1. Temporary redirection
command>& File Descriptor

[email protected] ~]# cat h.sh
#! /bin/bash
echo ' Test error ' >&2
echo ' normal output '
[Email protected] ~]# chmod u+x h.sh
[Email protected] ~]#./h.sh
Test error
Normal output
[Email protected] ~]#/h.sh 2>errlog
Normal output
[email protected] ~]# cat ErrLog
Test error
2. Permanent redirection
EXEC file descriptor > file name
[email protected] ~]# cat h.sh
#! /bin/bash
EXEC 1>output
echo ' Test error ' >&2
Echo ' OUTPUT1 '
echo "Output2"

[Email protected] ~]#./h.sh
Test error
[[email protected] ~]# cat output
Output1
Output2
h.sh Content
Figure 9
[Email protected] ~]#./h.sh
[[email protected] ~]# cat output
Output1
Output2
[email protected] ~]# cat Output_err
Test error
Test Error2

Input redirect
EXEC 0<filename
h1.sh Content
See Figure 10
[Email protected] ~]# chmod u+x h1.sh
[Email protected] ~]#./h1.sh
Line #1: Test error
Line #2: Test Error2

Pipeline
Redirect the output of one command to the input of another command
Command1|command2

2 commands are performed at the same time instead of executing one before continuing the next
Tee Output to File
[[Email protected] ~]# Date
Sunday, October 16, 2016 09:52:05 EDT
[Email protected] ~]# date|tee datefile
Sunday, October 16, 2016 09:52:17 EDT
[email protected] ~]# cat Datefile
Sunday, October 16, 2016 09:52:17 EDT

Variables in shell programming
User-defined variables
System Environment variables
by scope of action
Custom variables in the script
Environment variables
Local Environment variables
Global environment variables

Custom variable rules in shell scripts
Legal characters: Letters, numbers, underscores
Number of legal characters: <=20
Special note: Case sensitive

Variable declaration
Variable name = variable value such as Var=1
Type of variable value: Auto-assign number, string date, array
Call Mode: $ variable name such as $var
Scope: Within the lifetime of the script

' Can assign the result of the command execution to the variable
[[Email protected] ~]# Date
Sunday, October 16, 2016 10:10:02 EDT
[[email protected] ~]# mdate= ' Date '
[Email protected] ~]# echo $mdate
Sunday, October 16, 2016 10:10:23 EDT
Mdate= ' Date +%y-%m-%d '
Echo $mdate
2016-10-16

Input and output in the shell (Bash Shell 03)

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.