Basicintroduction
Inotherwords,shellscriptisaprogramwrittenbyusingthefunctionoftheshell.ThisprogramusesaplaintextfiletocombinesomeshellsyntaxandinstructionsWriteinit,andthenusefunctionssuchasformalnotation,pipelinecommands,anddataflowredirectiontoachievetheprocessingpurposewewant.
Tobemoreclear,shellscriptislike.batintheearlyDOSera.Thesimplestfunctionistocompilemanycommandstogether,sothatuserscaneasilyperformmultipleoperationsinoneoperation.Commands,andshellscriptprovidesimportantfunctionssuchasarrays,loops,conditions,andlogicaljudgments,allowinguserstowriteprogramsdirectlyinshellinsteadofusingthesyntaxoftraditionalprogramslikeCprogramminglanguage.
Conceptualdifference
Whatisthedifferencebetweenshellandshellscript?Tobeprecise,Shellisacommandlineinterpreter,itsroleistofollowacertaingrammartointerprettheinputcommandsandpassthemtothesystem.Itprovidesuserswithaninterfacesystem-levelprogramthatsendsrequeststoLinuxtorunprograms.UserscanuseShelltostart,suspend,stop,andevenwritesomeprograms.ShellitselfisaprogramwritteninClanguage,itisabridgeforuserstouseLinux.Shellisbothacommandlanguageandaprogramminglanguage(theshellscriptyoucall).Asacommandlanguage,itinteractivelyinterpretsandexecutescommandsenteredbytheuser;asaprogramminglanguage,itdefinesvariousvariablesandparameters,andprovidesmanycontrolstructuresthatareonlyavailableinhigh-levellanguages,includingloopsandbranches.AlthoughitisnotpartoftheLinuxsystemkernel,itcallsmostofthefunctionsofthesystemkerneltoexecuteprograms,createdocuments,andcoordinatetheoperationofvariousprogramsinaparallelmanner.
Scriptintroduction
Shellscript
Openatexteditor(youcanusevi/vimcommandstocreateafile),createanewfiletest.sh,extensionForsh(shstandsforshell),theextensiondoesnotaffecttheexecutionofthescript.Itisgoodtoknowwhatthenamemeans.Ifyouusephptowriteashellscript,usephpfortheextension.
Entersomecode,thefirstlinegenerallylookslikethis:
#!/bin/bashecho"HelloWorld!"
"#!"isaconvention,Ittellsthesystemwhatinterpreterthescriptneedstoexecute,thatis,whichkindofShellisused.
Theechocommandisusedtooutputtexttothewindow.