我正在写的应该在Unix上,Cygwin的,和MSYS工作一个跨平台的shell脚本。在我的shell脚本我需要执行与提升权限的操作。在Unix上,你将通过须藤做到这一点,并在的 Cygwin的通过类似 cygstart --action =运行方式 。什么是对MSYS等价?
I'm writing a cross-platform shell script that's supposed to work on Unix, Cygwin, and msys. In my shell script I need to perform actions with elevated privileges. On Unix you would do this via sudo, and on Cygwin via something like cygstart --action=runas. What's the equivalent for msys?
我所有的谷歌搜索至今只止跌回升这,这是不实际的距离一个shell脚本,因为你必须与GUI交互。
All my Googling so far has only turned up this, which isn't practical from a shell script since you have to interact with the GUI.
推荐答案我想我可能已经找到使用PowerShell的一个解决方案:
I think I may have found a solution using PowerShell:
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" }绝对是位非常的hackish,但总比没有好。 (或批处理文件,为这一问题。)
Definitely a bit Extremely hackish, but it's better than nothing. (Or Batch files, for that matter.)
更多推荐
什么是须藤在MSYS等价?
发布评论