shell script

selectr.name,count(p.id)frompersonsaspjoinridesasronp.fav_ride_id=r.idgroupbyr.idorderbycount(p.id)desclimit2;

一整就用到

$PWD
$PATH
$HOME

Theshellhasvariablestoaccessargumentsintheprocedures,todefinetheenvironmentandthelike.Shellvariablesare:

$1        # argument ($0..$9, $#)
PATH      # predefined symbol
mydir     # user defined symbol

Symbolsarecreatedusingthe=operator(noblanksallowed),thus:

mydir=`pwd`#mydirkeepstrackofcurrentworkingdirectory

Thesymbolmydircanbeusedtorestorethecurrentworkingdirectory,asshownbelow:

$cdgks/work#changeworkingdirectory

$mydir=`pwd`#setsymbolmydir

$cd#restorerootdirectory

$cdnew#movetonewdirectory

$cd$mydir#returntopreviousdirectory

Thecommandsetlistsallavailablesymbolsinthecurrentsession.Anyvariableisdefinedonlyinthecurrentsubshell,tomakethevariableglobaltoanysubshellusetheexportcommandasshownbelow.

Localdefinitionofmydir:

$mydir=`pwd`

$echo$mydir#printsthecurrentdirectory(i.e./u/codeorthelike)

$sh#runnewshell

$echo$mydir#mydirisnotdefinedatsubshell

Globaldefinitionofmydir:

$mydir=`pwd`;exportmydir

$echo$mydir#printsvalueofcurrentdirectory(i.e./u/code...)

$sh#runnewshell

$echo$mydir#valueofmydirissameasabove(i.e./u/code...)

PredefinedvariableslikePATHcanbechangedonlyatcurrentshelllevel:

$PATH=$PATH:/new

Tochangethevariablein.profileandhaveitactivethe(dot)commandmustbeused:

$../.profile

Thecommand:

$sh.profile

doesnotchangethevalueofPATHasitisexecutedinasubshell,using.(dot)meansuse.profileasstandardinputsothatthecommandsarereallyexecutedintheactiveshell.

IncasesomeapplicationsrequiretochangethevalueofPATHduringasessionwithoutmodifying.profile,editafile(ex.newp)containingacommandasfollows:

$ PATH=$PATH:/newdir
then type:
$ . ./newp

tosetthenewpathvalue.IncaseyouwanttorestorethedefaultPATH,use:

$ cd
$ . ./.profile
to reset the .profile setup.

相关推荐