Skip to content

Instantly share code, notes, and snippets.

@jagannath-sahoo
Created July 1, 2024 16:34
Show Gist options
  • Save jagannath-sahoo/21c52aefec2689a46423e0901749c08d to your computer and use it in GitHub Desktop.
Save jagannath-sahoo/21c52aefec2689a46423e0901749c08d to your computer and use it in GitHub Desktop.
Linux path to windows path
#!/bin/bash
# Get the drive letter and Linux path arguments
drive_letter="$1"
linux_path="$2"
# Check if arguments are provided
if [ -z "$drive_letter" ] || [ -z "$linux_path" ]
then
echo "Error: Please provide both drive letter and Linux file path as arguments."
exit 1
fi
# Convert forward slashes (/) to backslashes (\) using sed
windows_path=$(echo "$linux_path" | sed 's/\//\\/g')
# Prepend drive letter with colon (:) and combine with path
windows_path="$drive_letter:$windows_path"
# Convert drive letter to lowercase (optional)
windows_path=$(tr '[:upper:]' '[:lower:]' <<< "$windows_path")
# Print the converted Windows path
echo "Windows path: $windows_path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment