Skip to content

Instantly share code, notes, and snippets.

@Zero-Fanker
Last active September 9, 2021 05:27
Show Gist options
  • Save Zero-Fanker/158fb9825594614ed60a68a18abdd033 to your computer and use it in GitHub Desktop.
Save Zero-Fanker/158fb9825594614ed60a68a18abdd033 to your computer and use it in GitHub Desktop.
fake sudo for windows shell
#!/bin/sh
cmdStr=""
lastIsSlash=0
isFirstCmd=1
for cmd in $*;do
if [ $isFirstCmd -ne 0 ];then
isFirstCmd=0
if [ $cmd == su ];then
continue
fi
if [[ $cmd == -* ]];then
lastIsSlash=1
continue
fi
fi
if [ $lastIsSlash -ne 0 ];then
if [[ $cmd == -* ]];then
continue
else
lastIsSlash=0
fi
fi
cmdStr="$cmdStr $cmd"
done
# echo $cmdStr
if [ ${#cmdStr} -ne 0 ];then
$cmdStr
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment