I need a regular expression that will delete the last slash “/” in a line, and everything to the left of it.
I want to turn the full path to a package
/Volume/Installer/InstallerPackage.pkg
into just the name of the package
InstallerPackage.pkg
I will be using this in postflight scripts if I want to delete the package reciept.
Unless there is an Installer.app Environmental Positional Variable for the package name, I figured a regex was the way to go.
Here is an example of my postflight script.
#!/bin/bash
# postflight script
# Installer.app Environmental Positional Variables.
# $0 Script path
# $1 Package path
# $2 Default location
# $3 Target volume
# Declare the Enviromental Positional Variables so the can be used in function calls.
ScriptPath=$0
PackagePath=$1
DefaultLocation=$2
TargetVolume=$3
PackageName=${PackagePath”MagicRegEx”}
RemovePackageReceipt () {
rm -rf “${TargetVolume}/Library/Receipts/${PackageName}”
echo removed “${TargetVolume}/Library/Receipts/${PackageName}”
}
RemovePackageReceipt