Linux programming-11. ShellScript (bash) -- (2) tutorial

Source: Internet
Author: User
Article title: Linux programming-11. ShellScript (bash) -- (2) Tutorial example. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
"Hello world" Shell Script
According to the traditional program teaching example, this section describes how to write "Hello World" of Shell Script.
  
  
  
--------------------------------------------------------------------------------
  
#! /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.
[Foxman @ foxman bash] # chmod 755 hello
Run
[Foxman @ foxman bash] #./hello
Hello world
  
  
  
--------------------------------------------------------------------------------
  
Type 2: Use the bash built-in command "source" or ".".
[Foxman @ foxman bash] # source hello
Hello world
Or
[Foxman @ foxman bash] #. hello
Hello world
  
  
  
--------------------------------------------------------------------------------
  
Third, run the sh/bash/tcsh command directly.
[Foxman @ foxman bash] # sh hello
Hello world
Or
[Foxman @ foxman bash] # 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.
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.