Answers for "sudo in msys2"

0

sudo msys2

escape()
{
    RESULT="$1"
    RESULT="${RESULT/'/\''}" # replace ' with ''
    RESULT="${RESULT/"/\\\"}" # replace " with \"
    echo "''$RESULT''" # PowerShell uses '' to escape '
}

sudo()
{
    ESCAPED=()
    for ARG in "$@"
    do
        ESCAPED+=($(escape "$ARG"))
    done

    SHELL_PATH=$(cygpath -w $SHELL)
    PS_COMMAND="[Console]::In.ReadToEnd() | Start-Process '$SHELL_PATH' '-c -- "${ESCAPED[*]}"' -Verb RunAs"
    cat /dev/stdin | powershell -NoProfile -ExecutionPolicy Bypass "$PS_COMMAND"
}
Posted by: Guest on April-16-2020

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language