-3

I want to make an alias for sudo i.e.

alias now="echo [password] | sudo -S"

but it doesn't seem to work...

I was thinking that something like the following would work

alias now="echo [password] | sudo -S ${command_line_parameter}"

but I don't know what "${command_line_parameter}" would be... Any ideas?

1 Answers1

0

This post is only aimed to answer the how to of your question, however as others suggest it, you should consider implementing your desired rules in /etc/sudoers file, something like:

james  ALL=(ALL:ALL) NOPASSWD: /bin/ls

You can't pass an argument to an alias in a way you are doing it, you can use "functions" instead:

now(){ echo $1 | sudo -S $@ }

and use it like:

now password

If you want to hardcode your password:

now(){ echo your-password | sudo -S $@ }

Which non of them are a good thing to do at all, it's like giving your password away.

Ravexina
  • 57,256