Bug Report – nrf_sniffer_ble.sh: Virtual Environment Detection Fails Due to Syntax Error

In the nrf_sniffer_ble.sh script, the block that checks for an active virtual environment uses the following line:

if [ ! -z "$VIRTUAL_ENV"];

Notice that there is no space before the closing bracket. According to shell syntax, a space is required before the closing bracket. The correct line should be:

if [ ! -z "$VIRTUAL_ENV" ];

Because of this syntax error, the script fails to detect when a virtual environment is active. As a result, it falls back to using the system’s Python interpreter rather than the one in the virtual environment. This can lead to issues (e.g., “pyserial not found”) when dependencies are installed only in the virtual environment.

Steps to Reproduce:

  1. Create and activate a virtual environment (e.g., using python3 -m venv venv and source venv/bin/activate).

  2. Navigate to the folder containing nrf_sniffer_ble.sh.

  3. Run the command:

    sh
    Copy
    ./nrf_sniffer_ble.sh --extcap-interfaces
  4. Observe that the script outputs that it is running with the system’s Python (e.g., /opt/homebrew/bin/python3) and reports that required packages (like pyserial) are not found, even though they are installed in the virtual environment.

Expected Behavior:
When a virtual environment is active (i.e., $VIRTUAL_ENV is set), the script should detect it and use the Python interpreter from the virtual environment (via which python), ensuring that all dependencies installed there are available.

Observed Behavior:
Due to the missing space before the closing bracket in the if-statement, the script does not properly detect the virtual environment and instead uses the system’s Python interpreter. This results in errors such as “pyserial not found” if the system interpreter does not have the required dependencies.

Environment Details:

  • OS: macOS (example: Monterey)

  • Python Version: Managed via Homebrew (e.g., /opt/homebrew/bin/python3)

  • nRF Sniffer Version: 4.1.1

  • Additional Notes:
    The issue can be resolved locally by correcting the if-statement syntax. Consider also updating the script to explicitly prefer the virtual environment’s Python if $VIRTUAL_ENV is set.

Recommendation:
Please update the script by adding the missing space before the closing bracket:

if [ ! -z "$VIRTUAL_ENV" ];

This change will allow the script to correctly detect an active virtual environment and use the correct Python interpreter.