Linux program - 11.SHELL Script (Bash) - (2) Teaching example

xiaoxiao2021-03-06  95

"Hello World" Shell Script Photo of Traditional Program, this section introduces how shell Script "Hello World" writes. -------------------------------------------------- ------------------------------ #! / bin / sh # filename: Hello Echo "Hello World!" ---- -------------------------------------------------- -------------------------- Everyone should pay attention to "#! / Bin / sh" of the first line. Under UNIX, all can perform Script, whether it is the language, its start is "#!", Such as Perl is "#! / Usr / bin / perl", TCL / TK is "#! / Usr / BIN / WISH, see where the Script program you want to perform is there. You can also use "#! / Bin / bash", "#! / Bin / tcsh", etc. to specify the use of a specific shell. Echo is a BASH built-in instruction. -------------------------------------------------- ------------------------------ Next, execute Hello this Script: There are many ways to perform a script. -------------------------------------------------- ------------------------------ The first: set the permissions of this file to be executable. [Foxman @ Foxman Bash] # chmod 755 Hello Perform [Foxman @ Foxman Bash] # ./hello Hello World --------------------------- -------------------------------------------------- --- Second: Use the Bash internal instruction "source" or ".". [Foxman @ Foxman Bash] # Source Hello Hello World or [Foxman @ Foxman Bash] #. Hello Hello World --------------------------- -------------------------------------------------- --- Third: Directly use the SH / BASH / TCSH instruction to execute. [Foxman @ Foxman Bash] # sh Hello Hello World or [Foxman @ Foxman Bash] # Bash Hello Hello World --------------------------- -------------------------------------------------- --- Bash execution option -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------- -c string: Read the string to command. -I: interactive interface. -S: Read commands by stdin. -: Cancel the read option. -Norc: Do not read ~ / .bashrc. -Noprofile: Do not read /etc/profile ,~/.bash_profile ,~/.bash_login ,~/.profile, etc.

转载请注明原文地址:https://www.9cbs.com/read-122153.html

New Post(0)