Skip to content

Instantly share code, notes, and snippets.

@pekhota
Created July 19, 2023 19:03
Show Gist options
  • Save pekhota/639979692eb8aad43bf213ee215cdb08 to your computer and use it in GitHub Desktop.
Save pekhota/639979692eb8aad43bf213ee215cdb08 to your computer and use it in GitHub Desktop.
Gets the full path to the file
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