3

I'm trying to run this script as part of generating documentation using appledoc plug in. But, I'm receiving this 'Expected end of line but found identifier.' error when I run this script in Xcode(or terminal). Please help me out as I'm new to scripting and i'm unable to identify the exact error in the code!

#!/bin/bash
tmpdir="tmpdocs"
finaldir="docs"

rm -rf $tmpdir
mkdir $tmpdir # we killed this last time, create it to avoid warnings from appledoc

cd ./AppledocTemplates/
git checkout master
git pull origin master
expectedversion=$(./templateversion.sh) # Check repo version
cd ..

##########################################
# Install templates if not current
##########################################
if [ ! -f ~/.appledoc/templateversion.sh ]  #If this file doesn't exist, then need to install templates
then
  cd ./AppledocTemplates/
  ./installtemplates.sh 
  if [ $? -ne 0 ] # Descriptive error message is sent in installtemplates. Just exit with error
  then
    exit 1
  fi
  cd ..
fi

version=$(~/.appledoc/templateversion.sh) # Check installed version

if [ $version -ne $expectedversion ]
then
  echo "Updating templates"
  cd ./AppledocTemplates/
  ./installtemplates.sh #wrong version - try installing
  version=$(~/.appledoc/templateversion.sh)
  if [ $? -ne 0 ] # Descriptive error message is sent in installtemplates. Just exit with error
  then
    cd ..
    exit 1
  fi

  if [ $version -ne $expectedversion ] # Now is the version correct? If not, exit with error
  then
    cd ..
    echo "You do not have the correct version of the appledoc templates"
    echo "Make sure you run installtemplates.sh to put them in their correct location."
    exit 1
  fi
  cd ..
fi

##########################################
# Compile the docs
##########################################

appledoc ./AppledocSettings.plist MySDK # Compile the docs
if [ $? -ne 0 ]
then
  echo "Compile failure of source documents. MySDK doc creation not completed."
  exit 1
fi

##########################################
# Stage docs in proper places and cleanup
##########################################

#Move the docs to final directory
rm -rf $finaldir # clean out whatever was in the final dir
mkdir $finaldir # and recreate it

#Copy the docset file to the docs directory so that it can be loaded into github
cp -a ~/Library/Developer/Shared/Documentation/DocSets/us.MySDK.MySDK-Total-SDK.docset ./$finaldir
if [ $? -ne 0 ]
then
  echo "Unable to copy docset to ./docs" 
  exit 1
fi

# stage the html directories to their final destination
mv -f ./$tmpdir/html/* $finaldir
if [ $? -ne 0 ]
then
  echo "Unable to move html files to ./docs" 
  exit 1
fi

rm -rf $tmpdir #clear out the tmp dir

echo "MySDK doc creation successful."
exit 0

This is the log screen shot if I run the script from the terminal. This is the log screen shot if I run the script from Xcode.

The first one is the log screen shot if I run the script from the terminal. Second is the log screen shot if I run the script from Xcode.

rak appdev
  • 717
  • 8
  • 21
  • At the very end of the file, where it says "exit 0" leave two blank new lines ( give enter two times ) and try again. Let us know if that fixed your issue. – Matias Barrios Oct 03 '17 at 16:58
  • 1
    You cannot place a `bash` _script_ within an AppleScript document in the manner shown in the image in your OP. Script Editor cannot compile standalone raw `bash` _script code_ ! – user3439894 Oct 03 '17 at 17:00
  • @Matias Barrios, Your commit will not fix this issue! See my comment as to why. – user3439894 Oct 03 '17 at 17:01
  • @user3439894 Oh! Sorry I did not read the question correctly. – Matias Barrios Oct 03 '17 at 17:04
  • @user3439894 updated my post. Do you see anything wrong with the script syntax itself! – rak appdev Oct 03 '17 at 17:19
  • Okay, so you removed the picture from the OP but the question remained the same and therefore, as I've already said... You cannot place standalone raw `bash` _script code_ within an AppleScript document because Script Editor cannot compile standalone raw `bash` _script code_! As to, do I "see anything wrong with the script syntax itself", yes! Run your _shell code_ through: [ShellCheck](http://www.shellcheck.net/) – user3439894 Oct 03 '17 at 18:51
  • @user3439894 it's not about apple script. I was going through some SO posts and assumed that 'apple script' can be used to validate my script. Apologies for that! Coming to the original question, let me update the question with Xcode error screen shots! – rak appdev Oct 03 '17 at 21:03

0 Answers0