Page 1 of 1

Linux Scripting

Posted: Wed Feb 10, 2016 2:33 am
by lilzz

Code: Select all

jsr=''
execPlat=`$jsr GetPlat`

if [ "X$execPlat" = "XUNKNOWN" ]; then
  echo "Error: Unsupported platform.${NL}${suppPlats}"
  exit 1
fi 

GetPlat () {
  if [ -x /bin/uname ]; then 
    unameResult=`/bin/uname -a`

 platForm=`echo $unameResult | awk '{print $1}'`
}
1) GetPlat is a function, but why put '$jsr GetPlat' ? $jsr is an empty string
can I just do 'GetPlat'?
2)what difference is single quote versus double quote. They both can evaluate functions inside

Re: Linux Scripting

Posted: Wed Feb 10, 2016 2:42 am
by lilzz

Code: Select all

if $jsr CheckCDROM $cdPathDir; then 
  $jsr EchoN "${NL}Located CDROM at $cdPathDir ${NL}"
else

waht's this EchoN and why in bracket? ${NL}

Re: Linux Scripting

Posted: Wed Feb 10, 2016 6:32 am
by rpdom
1. jsr was possibly set to some special value for debugging the script? Who knows...

2. There are three types of quotes used in that script fragment. The normal double quote ("), single quote(') and back ticks (`). There are subtle differences between the way the shell handles things with the first two types, but mostly they can be used interchangeably. The backticks have a very special meaning, although in Bash I prefer to use the $() construct which is easier to read, can be nested and doesn't get confused by quotes so often.

3. Putting curly braces around a variable name is a way of delimiting the name. What would have happened if you left them out?

Code: Select all

if $jsr CheckCDROM $cdPathDir; then
  $jsr EchoN "$NLLocated CDROM at $cdPathDir $NL"
else
The shell will now try to echo the contents of a variable called NLLocated, instead of one called NL followed by the word "Located".