The issue is that you're checking if a directory exists (test -d), but based on the variable name FILE_PATH, it seems like you want to check if a file exists.
The -d flag in test -d specifically checks for directories. If $ABSOLUTE_FILE_PATH points to a regular file, the condition will be false even if the file exists.
To fix this, you should use:
test -f to check if it's a regular file
test -e to check if it exists (whether file or directory)
Here's the corrected version:
echo "Enter file path: "
read FILE_PATH <&1
ABSOLUTE_FILE_PATH="${PARENT_DIR}/${FILE_PATH}"
if ! test -f "$ABSOLUTE_FILE_PATH"; then
echo "$ABSOLUTE_FILE_PATH does not exist"
return
fi
Also note that I added quotes around "$ABSOLUTE_FILE_PATH" in the test command - this prevents issues if the path contains spaces or special characters.