Add Entry to PATH Variable on macOS 10 Sierra: for Current Terminal Session, Permanently for Current User and Permanently for All Users (Global)

This post shows how the PATH variable can be set on macOS 10 Sierra for the current terminal session only, permanently for the current user only and permanently for all users on the system.

In this example, the Tomcat startup.sh executable is added to the PATH variable so that is can be run from the terminal without having to use the full path name.

Summary

  1. Add Entry to PATH Variable for the Current Terminal Session Only
  2. Add Permanent Entry to PATH Variable for the Current User Only
  3. Add Permanent Entry to PATH Variable for all Users on the System (Global)

  • Open a new terminal window and use the echo command to view the PATH variable.
echo $PATH
  • By default, the variable should be set to something like this on macOS 10 Sierra (here 10.12.5):
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

macOS 10 Sierra Terminal - view current PATH variable

  • On my system, the Tomcat home is located at /Applications/apache-tomcat-9.0.0.M17
  • Staring the server using the startup.sh, requires using the full path name, otherwise it is not found.
sudo startup.sh

macOS 10 Sierra  Terminal - run Tomcat startup.sh

  • To add the Tomcat bin folder to the PATH variable for the current terminal session only, execute:
PATH=$PATH:/Applications/apache-tomcat-9.0.0.M17/bin
  • Use echo again to confirm the new entry to PATH:

macOS 10 Sierra  Terminal - add entry to PATH variable for current session

  • For the current terminal session, Tomcat can now be started by running startup.sh from any location.

macOS 10 Sierra  Terminal - run Tomcat startup.sh - server started successfully

  • This PATH entry will be lost when closing the current terminal or when opening a new terminal window.

  • To permanently add a PATH entry for the current user, navigate to the home folder:
cd $home
  • And execute the below command to edit the user’s bash profile. Bash is the default shell on macOS.
nano ~/.bash_profile

macOS 10 Sierra  Terminal - Start nano to edit user bash profile

  • Add the desired PATH entry with e.g. GNU nano as shown below. Use CTRL+O to save changes and CTRL+X to exit.

macOS 10 Sierra  Terminal - Use nano to edit user's bash profile and add entry to PATH variable

  • For the changes to take effect, close the current terminal window and open a new one.
  • Use echo $PATH again to confirm the entry was added.

macOS 10 Sierra  Terminal - confirm PATH entry was added to current user's bash profile

  • Whenever a terminal is opened by the current user, the bash profile will add the specified PATH entry.

  • To permanently add a PATH entry for all users on the macOS system (global), the /etc/paths file is used.
  • Open the file for editing by running:
sudo nano /etc/paths

macOS Terminal - view /etc/paths file and use nano to open for edit

  • Add the desired PATH entry as shown below. This file maintains a list of PATH entries, one per row:

macOS 10 Sierra  Terminal - edit /etc/paths file with nano and add entry to PATH variable for all users

  • Use CTRL+O to save changes and CTRL+X to exit.
  • Switch to another user on the Mac and confirm that the PATH entry is present.

macOS 10 Sierra  Terminal - confirm different user sees new PATH entry in /etc/paths

  • Note: In this example, the user edgar will only be able to actually run the Tomcat startup.sh if the permissions have been set correctly by the user that owns the files. Refer to chmod for setting permissions.
  • If read and execute permissions have not been set, errors indicating that the file was not found and other permission errors will occur.
  • Please register to leave a comment if you know additional or better approaches.

How to Use Expressions and Pega 7 Library Functions for String Manipulations in a Data Transform or Activity

For this post, Pega 7.1.9 was used. Pega 7 (and earlier versions) provides several utility functions for manipulating Strings.
These functions can be called as part of Expressions in Data Transforms and Activities.

Summary

  1. Sample Data Transform and Debugging
  2. Examples of String Manipulations with Expressions and Functions
    1. Conversion to Upper- and Lower Case
    2. Extraction of Substrings
    3. String Comparison
    4. Substring Search
    5. Substring Replace
    6. String to Number Conversions

Related Posts

  • For this example, a data transform with 7 input parameters was created:

Data Transform - TransformNames - Parameters Tab

  • On the Definition tab, the Set action is used to assign new values to the parameters using expressions. Here, Param.fullName is set using concatenation and conversion to upper case.

Data Transform - TransformNames - Set Action and Expression Builder Gear Icon

Data Transform - TransformNames - Pega 7.1.9 Expression Builder

  • The data transform can be run by clicking on Actions > Run.
  • Use the Trace button to start the Tracer. This allows to view the transformed input parameter values.

Data Transform - TransformNames - Run Data Transform Page

  • The data transform’s execution page can be viewed by clicking on the FIRST row in the Tracer (…execution page state after running the data transform).

Data Transform - TransformNames - Run Data Transform - Steps Execution and debugging in Tracer

  • Click on the =unnamed= link in the Parameter Page Name row to open the parameter page.

Data Transform - TransformNames - Tracer Debugging - View Trace Event

  • Here, the parameter page shows the data transform’s parameters AFTER execution is completed.

Data Transform - TransformNames - Tracer Debugging - View Data Transform Parameter Page

  • The Pega 7 String Library functions use the methods of the java.lang.String class. But, NOT ALL methods of java.lang.String are included in the Pega 7 String library.

A: Conversion to Upper- and Lower Case

  • Changing the case of a String is straightforward. Here, a single input String is converted to upper case.
    @String.toUpperCase(Param.firstName)
    "ULYSSES"
  • Likewise, a method exists for changing the case of a single input String to lower case.
    @String.toLowerCase("Ulysses S. Grant")
    "ulysses s. grant"
  • The + operator can be used for concatenating multiple parameters to one input parameter:
    @String.toLowerCase(Param.firstName + " " + Param.middleName + ". " + Param.lastName)
    "ulysses s. grant"

B: Extraction of Substrings

  • There are two overloaded @String.substring methods (same name, different input parameters) that can be used to extract a substring from a given string. The first one has 3 input parameters, the string (zero indexed) and a start-(inclusive) and end index (exclusive) and uses to the Java method substring(int beginIndex, int endIndex).
    @String.substring("304-678-9185 EXT 776", 0, 12)
    "304-678-9185"
  • To extract the last 4 digits of the phone number:
    @String.substring("304-678-9185 EXT 776", 8, 12)
    "9185"
  • The second substring method only has 2 input parameters, the string and the start index.
  • To extract the extension in this example, use:
    @String.substring("304-678-9185 EXT 776", 17)
    "776"
  • The result of a function can be passed as an input parameter to another function. Here, the 10-digit phone number is extracted first. Then, the area code is extracted:
    @String.substring(@String.substring("304-678-9185 EXT 776", 0, 12), 0, 3)
    "304"
  • @String.length is used to obtain the length of a given string, i.e. the number of characters:
    @String.length("Blueberry")
    9

C: Comparison

  • @String.equalsIgnoreCase is used to compare two Strings (case-insensitive). For example:
    @String.equalsIgnoreCase(Param.firstName, Param.lastName)
    false
  • @String.notEqualsIgnoreCase is used to compare two Strings for INEQUALITY. For example:
    @String.notEqualsIgnoreCase(Param.firstName, Param.lastName)
    true
  • @String.equals is used for CASE-SENSITIVE comparison:
    @String.equals("Blue", "blue")
    false
  • @String.notEquals is used for CASE-SENSITIVE comparison for INEQUALITY:
    @String.notEquals("Blue", "blue")
    true

D: Substring Search

  • @String.contains is used to search for the occurrence of a given substring within a string:
  • Here, Param.street is "Oak Hill Dr" and the method is used to check if it contains "Hill".
    @String.contains(Param.street, "Hill")
    true
  • @String.pxContainsViaRegex is used to search for the occurrence of a given substring within a string using a regular expression. For details on regular expressions, see the java.util.regex.Pattern class documentation.
  • In this example, a regular expression, \d{3}-\d{3}-\d{4}, is used to search for 10-digit phone numbers in a given String. Note that the \ character needs to be escaped as per Java syntax, using \\.
    @String.pxContainsViaRegex("phone=345-444-0001|name=smith", "\\d{3}-\\d{3}-\\d{4}", true)
    true
  • @String.startsWith is used to check if a string starts with a given substring.
  • @String.endsWith is used to check if a string ends with a given substring:
    @String.endsWith(Param.street, "Dr")
    true
  • @String.indexOf can be used to get the start index of a substring within a given String.
    @String.indexOf(Param.street, "Hill")
    4
  • If the given substring is NOT found, @String.indexOf returns -1, for example:
    @String.indexOf("Oak Hill Dr", "Blvd")
    -1
  • @String.indexOf is often used with @String.substring.
  • For example, Param.inputRow is "Name=Warren". To extract the actual name:
    @String.substring(Param.inputRow, @String.indexOf(Param.inputRow, "=") + 1)
    "Warren"

E: Substring Replace

  • @String.replaceAll is used to replace all occurrences of a given string with another string.
  • In this example, all of the hyphen characters are replaced with pipe characters:
    @String.replaceAll("apple-banana-cherry-date", "-", "|")
    "apple|banana|cherry|date"
  • @String.pxReplaceAllViaRegex is used to replace all substrings that match the given regular expression. For details on regular expressions, see the java.util.regex.Pattern class documentation.
  • For example, to replace all 10-digit phone numbers in a String with XXX-XXX-XXXX:
    @String.pxReplaceAllViaRegex(
    "Mr.Smith's work phone number is 675-999-0017 and his cell phone is 778-000-9999.",
    "\\d{3}-\\d{3}-\\d{4}",
    "XXX-XXX-XXXX")
    "Mr.Smith's work phone number is XXX-XXX-XXXX and his cell phone is XXX-XXX-XXXX."

F: String to Number Conversions

  • @String.isInteger is used to validate that a given String represents a number of type Integer:
    @String.isInteger("178")
    true
  • @String.isDouble is used to validate that a given String represents a number of type Double:
    @String.isDouble("199.49")
    true
  • Strings that represent Integer and Double type numbers can be converted to Integer and BigDecimal Java types:
    @String.toInt("149")
    149
  • If the String does not contain a valid Integer value, the function returns 0.
    @String.toInt("99.99")
    0
  • @String.toDecimal supports thousands separators and a decimal point:
    @String.toDecimal("1,250,599.39")
    1250599.39