Script to use "su" instead of "sudo"

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

Script to use "su" instead of "sudo"

#1 Post by s243a »

I wrote a script to use su instead of sudo:

Code: Select all

#!/bin/sh
cmd=""
function quote(){
  echo $1 | sed "s/'/'\"'\"'/g"
}
for arg in "$@"; do
  cmd="$cmd '$(quote "$arg")'"
done
su -c "$cmd" root
Testing the script:

Code: Select all

# bash su_sudo echo "a'b'c"
a'b'c
My idea here is in the winetricks script to use my "su_sudo" script if the sudo command can't be found. See post

I'll let everyone know if it works with wintricks. So we have in the wintricks script (around line 3169 in the version found in fatdog64 gsplat "wine 4.19-i686-1"):

Code: Select all

winetricks_detect_sudo()
{
    WINETRICKS_SUDO=sudo
    [ -z "$(which sudo)" ] && WINETRICKS_SUDO=su_sudo
Find me on [url=https://www.minds.com/ns_tidder]minds[/url] and on [url=https://www.pearltrees.com/s243a/puppy-linux/id12399810]pearltrees[/url].

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#2 Post by s243a »

The above script worked with winetricks. For further improvement, I think I should first replace "\" by "\\" before escaping the single quotes.
Find me on [url=https://www.minds.com/ns_tidder]minds[/url] and on [url=https://www.pearltrees.com/s243a/puppy-linux/id12399810]pearltrees[/url].

Post Reply