Shell Step by Step (1)--Introduction

Source: Internet
Author: User

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

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.