You are not logged in.
Pages: 1
is there any way to have options in a bash alias?
so for example i want "pacman -s" to alias "sudo pacman -S" so i add
" alias 'pacman -s'='sudo pacman -S' " to my bashrc, but this dont work.
does anyone konw how do to this or am i going to have to mak a script?
Offline
I don't think you can have spaces in aliases, IIRC. It should be possible to do it with a function, but using a script would be approximately equally simple to putting a function in your ~/.bashrc.
alternatively, I just have pacman aliased, and the sudo configuration takes care of options.
Dusty
Offline
I don't think you can have spaces in aliases, IIRC
that what i thought
It should be possible to do it with a function, but using a script would be approximately equally simple to putting a function in your ~/.bashrc.
i probably do a srcipt some thing like
#!/bin/bash
if [ $1 ] ; then
case $1 in
-s ) sudo pacman -S ;;
esac
else
echo "i need a option"
fi
and just fill out each option, its a pain in the arse and i was try to avoid it but... meh
alternatively, I just have pacman aliased, and the sudo configuration takes care of options.
Dusty
i was trying not to do this as i dot want to have to put in my passwd for a -Ss or -Qi
Offline
Why not just do
alias pacmans="sudo pacman -S"
or
alias pacinstall="sudo pacman -S"
Offline
i was trying not to do this as i dot want to have to put in my passwd for a -Ss or -Qi
I hate visudo syntax, but I know I had this at one point. I guess its like this:
Cmnd_Alias PACMAN = /usr/bin/pacman -[SUAQ]*
dusty ALL = NOPASSWD: PACMAN
Then I have sudo set up to allow my account to do password-protected sudo on all other options (ie: dusty ALL = (ALL) ALL
), so pacman -R, for example, requires a password (so does rm -rf!). Then I have
alias pacman='sudo /usr/bin/pacman'
in my .bashrc.
Dusty
Offline
I'm more self-trusting (or maybe reckless) than Dusty, so I have
tomk tk-i5ka= NOPASSWD: /usr/bin/pacman
in sudoers, and
alias pacman='sudo pacman'
in .bashrc - no password for any pacman commands.
Offline
Why not just do
alias pacmans="sudo pacman -S"
that what i have now
Dusty i'll have i look in to the sudo stuff. (but i dont think it will be with NOPASSWD tomk :shock:)
i think i add a function inmy bashrc like dusty said.
pacman () {
case $1 in
-s ) sudo pacman -S $2 $3 $4 $5 ;;
-S ) sudo pacman -S $2 $3 $4 $5 ;;
-su ) sudo pacman -Su $2 $3 $4 $5 ;;
-Su ) sudo pacman -Su $2 $3 $4 $5 ;;
-syu ) sudo pacman -Syu $2 $3 $4 $5 ;;
-Syu ) sudo pacman -Syu $2 $3 $4 $5 ;;
-R ) sudo pacman -Rs $2 $3 $4 $5 ;;
-r ) sudo pacman -R $2 $3 $4 $5 ;;
-* ) pacman $*
esac
}
is any way to do greater than $1 insted that doing "$2 $3 $4 $5"
Offline
is any way to do greater than $1 insted that doing "$2 $3 $4 $5"
opts=`echo ${@} |sed "s/${1}//"`
then you can use $opts
Offline
bash also breaks arguments at ' ', so just "$*" will work fine after you do a 'shift' to remove $1
Offline
bash also breaks arguments at ' ', so just "$*" will work fine after you do a 'shift' to remove $1
thanks shift worked
Offline
Pages: 1