I have a script that I wrote to switch to root or ran the command as root without a password. I edited the file / etc / sudoers so that my user [matt] has permission to run / bin / su without a password. This is my script "content:
matt: ~ $ cat ~/bin/s
#!/bin/bash
[ "$1" != "" ] && c='-c'
sudo su $c "$*"
If there are no parameters [simple s], it basically calls sudo suwhich goes to root without a password. But if I set the parameters, the variable $ c is equal to "-c", which makes su the execution of one command.
It works well, except when I need to use spaces. For instance:
matt: ~ $ touch file\ with\ spaces
matt: ~ $ s chown matt file\ with\ spaces
chown: cannot access 'file': No such file or directory
chown: cannot access 'with': No such file or directory
chown: cannot access 'spaces': No such file or directory
matt: ~ $ s chown matt 'file with spaces'
chown: cannot access 'file': No such file or directory
chown: cannot access 'with': No such file or directory
chown: cannot access 'spaces': No such file or directory
matt: ~ $ s chown matt 'file\ with\ spaces'
matt: ~ $
How can i fix this?
Also, what's the difference between $ * and $ @ ?