1. Read keyboard input
read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
- -p prompt statement, followed by the message input
- -n number of characters, the length limit input
- -s shielding echo, typing on the screen is not displayed, generally used for password entry
- -t timeout, timeout waiting for input
- -d input limit encountered the symbol, the input termination
- -r shielded special characters \ escape function
$ read -s -t 5 -n 6 -p "Enter password: " password
$ echo $password
2. echo escape output
$ echo "hello\n world." hello\n world. $ echo -e "hello\n world." hello world.
3. Redirection
Under normal circumstances, each Unix / Linux command is running will open three files:
- Standard input file (stdin): stdin file descriptor is 0, Unix default program data read from stdin.
- Standard output file (stdout): stdout file descriptor 1, Unix program default data output to stdout.
- The standard error file (stderr): stderr file descriptor 2, Unix program writes error information to stderr stream.
$ command < infile > outfile
Alternatively the input and output simultaneously, command <infile to redirect stdin to infile, then command> outfile redirect stdout, to the outfile.
(1) If you want to redirect stdout and stderr after the merger to file, write:
$ command > file 2>&1
(2) If you want to execute a command, but do not want to display the output on the screen, you can redirect the output to / dev / null:
$ command > /dev/null
/ Dev / null is a special file, its contents will be written to be discarded; if you try to read from the file, then nothing can not read.
(3) If you want to shield stdout and stderr, can be written:
$ command > /dev/null 2>&1