Bugfix Ventoy2Disk.sh: PATH broken when running from outside the script directory#3615
Open
tiagoapimenta wants to merge 1 commit into
Open
Bugfix Ventoy2Disk.sh: PATH broken when running from outside the script directory#3615tiagoapimenta wants to merge 1 commit into
tiagoapimenta wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Commit f7e4a7a changed
export PATHfrom"./tool/$TOOLDIR:$PATH"to"$OLDDIR/tool/$TOOLDIR:$PATH", whereOLDDIR=$(pwd)is captured at the script's very first line.This broke running
Ventoy2Disk.shfrom any directory other than the script's own directory. The reason is that line 7 conditionallycds into the script's directory when./tool/ventoy_lib.shis not found in the current directory. After thatcd,$OLDDIRstill holds the original working directory, so the PATH points to the parent directory'stool/instead of the script'stool/, causingvtoycli(and other tools) to not be found inVentoyWorker.sh.Changes
Proposal 1: Fix PATH resolution (must be evaluated after the
cdon line 7)Replace
$OLDDIR/tool/$TOOLDIRwith$(pwd)/tool/$TOOLDIR. After thecd "$(dirname "$0")"has run,pwdalways 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
cdbackReplace the complex conditional
cdlogic with a single unconditionalcd "$(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 — thecdback serves no purpose.