Skip to content

Bugfix Ventoy2Disk.sh: PATH broken when running from outside the script directory#3615

Open
tiagoapimenta wants to merge 1 commit into
ventoy:masterfrom
tiagoapimenta:fix-path
Open

Bugfix Ventoy2Disk.sh: PATH broken when running from outside the script directory#3615
tiagoapimenta wants to merge 1 commit into
ventoy:masterfrom
tiagoapimenta:fix-path

Conversation

@tiagoapimenta

Copy link
Copy Markdown

Motivation

Commit f7e4a7a changed export PATH from "./tool/$TOOLDIR:$PATH" to "$OLDDIR/tool/$TOOLDIR:$PATH", where OLDDIR=$(pwd) is captured at the script's very first line.

This broke running Ventoy2Disk.sh from any directory other than the script's own directory. The reason is that line 7 conditionally cds into the script's directory when ./tool/ventoy_lib.sh is not found in the current directory. After that cd, $OLDDIR still holds the original working directory, so the PATH points to the parent directory's tool/ instead of the script's tool/, causing vtoycli (and other tools) to not be found in VentoyWorker.sh.

Changes

Proposal 1: Fix PATH resolution (must be evaluated after the cd on line 7)

Replace $OLDDIR/tool/$TOOLDIR with $(pwd)/tool/$TOOLDIR. After the cd "$(dirname "$0")" has run, pwd always reflects the script's directory, so the tool path is always correct regardless of where the script is invoked from.

Proposal 2: Simplify directory detection and remove unnecessary cd back

Replace the complex conditional cd logic with a single unconditional cd "$(dirname "$0")". This is simpler, more robust, and works identically in all cases.

The trailing cd "$OLDDIR" block was also removed because a shell script's working directory changes do not propagate to the parent process — the cd back serves no purpose.

Commit f7e4a7a changed PATH from ./tool/$TOOLDIR to
$OLDDIR/tool/$TOOLDIR, but $OLDDIR is captured before the
conditional cd on line 7, so running from a parent directory
causes the PATH to point to the wrong location.

Replace the conditional cd + OLDDIR logic with a simple
cd "$(dirname "$0")" and use $(pwd) for PATH resolution.
The trailing cd-back is removed since script directory changes
do not affect the parent shell.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant