Created
July 19, 2023 19:03
-
-
Save pekhota/639979692eb8aad43bf213ee215cdb08 to your computer and use it in GitHub Desktop.
Gets the full path to the file
This file contains 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
path() { | |
local filename="$1" | |
local search_dir="$2" | |
if [ -z "$filename" ]; then | |
echo "Error: Filename argument is missing." | |
return 1 | |
fi | |
if [ -z "$search_dir" ]; then | |
search_dir=$(pwd) | |
fi | |
local result=$(find "$search_dir" -name "$filename" -print -quit 2>/dev/null) | |
if [ -n "$result" ]; then | |
echo "$result" | |
else | |
echo "File '$filename' not found in directory '$search_dir' or its subdirectories." | |
return 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment