Shell Learning notes-the first day

Source: Internet
Author: User

1. The first line of the program specifies the program that executes the shell

  #!/bin/sh

#! is used to tell the system that the parameter behind it is the program used to execute the file

2. Output information in the console

echo "Hello Shell"

#!/bin/sh#向控制台输出信息 echo"Hello Shell"

Save, quit!
3, make script executable, need to execute the following command in DOS window

chmod +x FileName

4. Execute script

./helloshell

5, the use of variables

In the shell, variables are not declared and can be used directly (similar to LUA)

Remove variables using dollar sign $

#变量的使用a="I am a variable"echo  $aecho ${a}

The curly braces are used to prevent variables from being adjacent to the string, and what is the indeterminate variable! such as: $numth and ${num}th The former variable named numth variable, the latter takes the variable named Num.

6. Shell Common Commands

File Statistics Command: wc–l filename, wc-w filename, wc-c filename: Calculates the number of file lines, calculates the number of words in the file, calculates the number of characters in the file

File copy: CP sourcefile DestFile
Renaming files or moving files: MV oldname newname
Delete Files: RM file

Search string in file (regular expression supported): grep ' str ' fileName outputs the rows that are searched to the console

Output file contents to screen: Cat FileName

  

  

Shell Learning notes-the first day

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.