Created
July 1, 2024 16:34
-
-
Save jagannath-sahoo/21c52aefec2689a46423e0901749c08d to your computer and use it in GitHub Desktop.
Linux path to windows path
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
| #!/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