1. View Current user (number of users) [email protected]: ~# who [| wc-l]
[email protected]: ~# who
Kallen Tty4 2015-01-16 10:46
Kallen tty5 2015-01-16 10:47
Kallen Tty2 2015-01-16 10:42
Kallen tty3 2015-01-16 10:42
Root Tty6 2015-01-16 10:58
Kallen tty1 2015-01-15 13:10
Kallen Tty7 2015-01-15 12:52
[email protected]: ~#
[email protected]: ~# who | wc-l
-
Convert pipe L to stand-alone command[email protected] :~#  CAT; ----creating files, using Cat copy terminal input [email protected" :~# &NBSP, who | wc-l ----script content
[email protected] :~# Span style= "line-height:1.5" > ctrl + D (end-of-file) ----end of file
[email protected" :~# chmod +x  COUNTUSERS  ----Let the file have Execute permissions
[email protected] :~# ./countusers ----Execute Script
" attached "WC command # Count Bytes Echo Testing one and three |
wc-c Print the byte counts (count bytes) # Count Rows Echo Testing one and three |
wc-l Print the character counts (count of characters) # Count Letters Echo Testing one and three |
wc-w Print the newline counts (count rows)
2. Script Declaration#!/bin/bash##!/bin/bash-
-Indicates that there is no shell option, which is based on security considerations and avoids some deceptive attacks (spoofing attack) #Shell's three basic commands: Built- in commands, shell functions, external commands
# View current shell type[email protected]:/# echo $SHELL
/bin/bash
# Shell script execution mode [email protected]:/# source Shellfile [email protected]:/# bash shellfile [email protected]:/# ./shellfile (file must have executable permissions chmod +x or chmod 755)
after writing the script, you can use sh scriptname, [or bash scriptname to invoke it.
(Sh scriptname is not recommended because it disables the ability of the script to read data from the stdin. )
using the SH scriptname to invoke the script will close some bash-specific extensions, and the script may fail to invoke it.)
A more convenient approach is to have executable permissions on the script itself, which can be modified through the chmod command.For example: chmod 555 scriptname (allows anyone to have read and execute privileges)or: chmod +rx scriptname (allows anyone to have read and execute privileges) chmod u+rx scriptname (only the owner of the script can read and Execute permissions)
Shell Step by Step (1)--Introduction