Shell Getting Started notes

Source: Internet
Author: User

Write the Hello World script and execute the script

Two methods

1, ls-a view all the files

2. mkdir test.sh Create a file named test.sh

3, CD test.sh into test.sh this file

4, Vim test.sh open vim and enter into test.sh this file

5, I (insert insertion, editing)

6. Write script

#!/bin/sh

#echo "123456" This behavior comment

echo "Hello World" echo for output command, the Hello World field will appear after the Echo Hello World return is written separately

7. ESC Exit Vim edit mode

8, input: After wq! Save the file and exit vim

9. After SH test.sh, Hello World appears.

Or

9. cd. Go back to the root directory

10, CHOMD +x./test.sh This step is test.sh this script has execute permissions

11./test.sh execution script appears Hello World

Note : Be sure to write./test.sh, not test.sh. Run other binary programs also, the direct write Test.sh,linux system will go to the path to find there is not called test.sh, and only/bin,/sbin,/usr/bin,/usr/sbin, etc. in path, your current directory is usually not in path, So write test.sh will not find the command, to use./test.sh tells the system that it is looking in the current directory. To run the bash script this way, the first line must be written so that the system can find the correct interpreter.
As an interpreter parameter, this runs the interpreter directly, whose arguments are the file names of the shell scripts, such as:
$/bin/sh test.sh
$/bin/php test.ph

Read command

1, ls-a view all the files

2. mkdir test2.sh Create a file named test.sh

3, CD test2.sh into test2.sh this file

4, Vim test2.sh open vim and enter into test.sh this file

5. Write script

#!/bin/bash

# Author:mozhiyan
# Copyright (c) http://see.xidian.edu.cn/cpp/linux/
# Script follows here:
echo "What's your name?" Enter a name manually, such as: WJ
Read person
echo "Hello, $PERSON" appears after carriage return as Hello WJ similar to scanner (scan) keyboard input

Shell Getting Started notes

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.