I'm writing a bash script. I need to introduce a colon after the first occurrence of a character.
/c/Users/ertwr/org/readme.html
and in order to open them with the native Windows browser the need a colon after the unit letter /c:/Users/ertwr/org/readme.html
I use the following expression which works remarkably well, even for multiple files or whitespaces, but only for the specified unit since I can't store the unit letter in the regular expression.
#!/usr/sbin/env bash
IFS=$'\n'
${HOME}/scoop/shims/chrome "${@/\/\c\//\c\:\/}"
The problem is it only works for the C
letter the way it's written. So I need a way to make it work independently for ANY letter.
Things I've tried and don't work for multiple files or files with spaces:
- can't capture the regex
I really want this one to work, but I'm doing something wrong.
#!/usr/sbin/env bash
IFS=$'\n'
regex=(\/[a-zA-Z]\/)
if [[ "$@" =~ "$regex" ]]; then
${HOME}/scoop/shims/chrome "${@/$BASH_REMATCH/${BASH_REMATCH}\:}"
fi
- sed append
#!/usr/sbin/env bash
IFS=$'\n'
WADDR=`sed 's|\<[a-zA-Z]\>|&:|' "$@"`
${HOME}/scoop/shims/chrome "${WADDR}"
Sed particularly feeds the content of the file as url, instead of the name of the file. While it works when using a text file as input.
/c/Windows/System32/notepad.exe "C:\path\to\file"
. Don't forget to mention the double quote.