Linux Shell Learning

Source: Internet
Author: User

"Hello World" shell script
Based on the traditional program teaching example, we will introduce how to write shell script "Hello World.

--------------------------------------------------------------------------------

#! /Bin/sh
# Filename: Hello
Echo "Hello world! "

--------------------------------------------------------------------------------

Everyone should notice the first line "#! /Bin/sh ". In UNIX, All executable scripts start "#! ", For example, Perl is "#! /Usr/bin/Perl ", Tcl/TK is "#! /Usr/bin/wish ", check where the script program you want to run is located. You can also use "#! /Bin/bash ","#! /Bin/tcsh "and so on to specify a specific shell.
ECHO is a built-in bash command.

 

--------------------------------------------------------------------------------

Next, execute the script Hello:
There are many ways to execute a script.

--------------------------------------------------------------------------------

First, set the "hello" File Permission to executable.
[Root @ RedHat proshell] # chmod 755 hello
Run
[Root @ RedHat proshell] #./Hello
Hello World

 

--------------------------------------------------------------------------------

Type 2: Use the bash built-in command "Source" or ".".
[Root @ RedHat proshell] # source hello
Hello World
Or
[Root @ RedHat proshell] #. Hello
Hello World

 

--------------------------------------------------------------------------------

Third, run the sh/bash/tcsh command directly.
[Root @ RedHat proshell] # sh hello
Hello World
Or
[Root @ RedHat proshell] # bash hello
Hello World

 

--------------------------------------------------------------------------------

Bash execution options

--------------------------------------------------------------------------------

-C string: Read string as a command.
-I: interactive interface.
-S: read command by stdin.
-: Cancel reading to the backend option.
-NORC: Do not read ~ /. Bashrc.
-Noprofile: Do not read/etc/profile ,~ /. Bash_profile ,~ /. Bash_login ,~ /. Profile and so on.
-Rcfile filename: Execute filename instead ~ /. Bashrc
-Version: displays the version.
-Quiet: do not roll it up at startup.
-Login: Make sure Bash is a login shell.
-Nobraceexpansion: Do not use the curly brace expansion ({}) symbol ).
-Nolineediting: read command columns without Readline.
-POSIX: POSIX 1003.2 standard.

(Reference: http://www.fanqiang.com)
 

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.