Bytes ----------------------------------------------------------------------------------------------------------
Command to complete most output tasks: Echo
Echo helloworld; # correct
Echo "Hello World"; # correct
Echo "Hello world! "; # A space must be enclosed in quotation marks! In Linux, double quotation marks are not allowed, but single quotation marks are used (NOTE: Some Linux systems can output normally, but this statement is not recommended)
Echo 'Hello world! '; # Correct
Command: help Echo or man echo # view the echo Command help
[Email protected] Black Eye poet <www. chenwei. ws> ---------------------------------
I. the first shell script:
VI hello. Sh # Linux scripts do not differentiate extensions, but end with. Sh to tell the system to write a shell script. A syntax color prompt is displayed when you use Vim to open the script.
#! /Bin/bash # mark the following program as a shell script. In addition to this sentence, all other statements starting with # indicate comments.
# The first program # Is a comment
# Author chenwei # Annotation
Echo-e "chenwei is Black Eyed poet" # Content
2. Two Methods for executing shell scripts:
1. Grant the execution permission to run directly
Chmod 755 hello. Sh
./Hello. Sh # It can be executed in absolute or relative paths.
2. Execute the script through bash call
Bash hello. Sh # execute bash directly without the execution permission.
Iii. tips:
Cat-a hello. Sh # Add the-A option to view the complete script content, including hidden characters
# Run the last command to view the shell script edited in Linux. The carriage return value is $, but for the shell script edited in windows, the carriage return value is ^ m $, in Linux, if you want to execute the edited script in windows, an error will be reported (the file or directory does not exist ).
Solution:
Command: dos2unix hello. Sh # convert from DOS to Unix. If this command is not installed in your system: Yum-y install dos2unix, similarly: Yum-y install unix2dos
Bytes --------------------------------------------------------------------------------------------------------