"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)