LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Howto pass an argument to alias of a script? (https://www.linuxquestions.org/questions/programming-9/howto-pass-an-argument-to-alias-of-a-script-621837/)

Goose1 02-17-2008 03:21 PM

Howto pass an argument to alias of a script?
 
Hi,
I have a script that needs to run as root. I have an alias for it:
alias my_script='su -c /path/path/path/my_script.sh \$*'

Now, I've added to the script some options that can be given as parameters from the command line. for example:
/path/path/path/my_script.sh 123

This works fine, but the alias doesnt pass that correctly...
$ my_script 123
su: user 123 does not exist
$

I've tryed all kind of combinations of "" '' `` but it didnt worked.
Can someone please advise?
Thanks!

rhapsody630 02-17-2008 06:14 PM

You need to change your alias
> alias my_script='su -c /path/path/path/my_script.sh \$*'

to
alias my_script='su -c /path/path/path/my_script.sh root'

Read the man page for su. The first argument, if given, is the user to su to.

The clue is in the error message
> su: user 123 does not exist
Your alias is passing 123 and su assumes that is the user.

You don't need the \$*.

You might do better to add the script that has to be run as root to those that sudo knows about, see visiudo, and use alias my_script="sudo my_script" instead.


All times are GMT -5. The time now is 06:02 AM.