You are not logged in.

#1 2008-12-06 14:10:18

okplayer02
Member
From: Denver, Colorado
Registered: 2008-11-24
Posts: 84

bashrc syntax (SOLVED)

say for instance id like to add an alias to my bashrc 

say like

alias removeallpa='su -c pacman -Rs'


so that i can use pacman to remove a file
what is the correct syntax for the command to get it working properly

i know on the command line when i run

su -c 'pacman -Rs firefox'

it works perfectly it prompts me for the password like i want
i just prefer not to use sudo any guidance how to get this to work i would appreciate thanks

Last edited by okplayer02 (2008-12-06 20:42:47)


Say what is good or keep silent  --Prophet Muhammad (SAW)

Offline

#2 2008-12-06 14:36:21

u_no_hu
Member
Registered: 2008-06-15
Posts: 453

Re: bashrc syntax (SOLVED)

try

alias supac="su -c 'pacman -Qi  firefox'"

Last edited by u_no_hu (2008-12-06 14:36:49)


Don't be a HELP VAMPIRE. Please search before you ask.

Subscribe to The Arch Daily News.

Offline

#3 2008-12-06 14:55:08

okplayer02
Member
From: Denver, Colorado
Registered: 2008-11-24
Posts: 84

Re: bashrc syntax (SOLVED)

ah yes it did work perfectly the syntax now how can i go about typing the particular command like


supac firefox

obviously i will be using other programs other than firefox

it seems like i will have to use sudo to get around this problem but just looking for another solution


Say what is good or keep silent  --Prophet Muhammad (SAW)

Offline

#4 2008-12-06 15:44:51

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: bashrc syntax (SOLVED)

You could use a function.

function supac
{
    su -c 'pacman -Qi $@'
}

I think that should work for you.

Offline

#5 2008-12-06 15:53:17

u_no_hu
Member
Registered: 2008-06-15
Posts: 453

Re: bashrc syntax (SOLVED)

alias supac="su -c 'pacman -Qi "

you will have to fill in the other quote while running the command ;-)  supac firefox'

and i dont know what will happen to other aliases if they are coming after this ... unchartered territory use at your own risk;-)


Don't be a HELP VAMPIRE. Please search before you ask.

Subscribe to The Arch Daily News.

Offline

#6 2008-12-06 16:03:03

okplayer02
Member
From: Denver, Colorado
Registered: 2008-11-24
Posts: 84

Re: bashrc syntax (SOLVED)

ah i see i will give a test try

so for my alias it would be like so

alias supac="su -c 'pacman -Qi'"

and as u explained  with the next function it will define the alias if im correct?

function supac
{
    su -c 'pacman -Qi $@'
}

i dont mind cause im getting a lesson now i wasnt planning but i appreciate the help guys i take all disclaimers of course.


Say what is good or keep silent  --Prophet Muhammad (SAW)

Offline

#7 2008-12-06 16:07:33

u_no_hu
Member
Registered: 2008-06-15
Posts: 453

Re: bashrc syntax (SOLVED)

dont close the  single quote ...  i feel terribly ugly recommending this...... big_smile


Don't be a HELP VAMPIRE. Please search before you ask.

Subscribe to The Arch Daily News.

Offline

#8 2008-12-06 17:19:46

okplayer02
Member
From: Denver, Colorado
Registered: 2008-11-24
Posts: 84

Re: bashrc syntax (SOLVED)

well i made a few adjustments to that function

function supac
{
    su -c 'pacman -Rs $@'
}

when i run

supac

it prompts for password then proceeds to list every package but if i do

supac firefox

it prompts for password then give the following message:

error: no targets specified (use -h for help)

like i say i seen this with sudo but surely it must be the same for su -c 
must be an way to get it working though i been looking at other examples but nothing so far


Say what is good or keep silent  --Prophet Muhammad (SAW)

Offline

#9 2008-12-06 20:29:50

klixon
Member
From: Nederland
Registered: 2007-01-17
Posts: 525

Re: bashrc syntax (SOLVED)

I think the '$@' doesn't get expanded because it's enclosed in single quotes.

This seems to work:

function supac {
  eval su -c \'pacman -Rs "$@"\'
}

Stand back, intruder, or i'll blast you out of space! I am Klixon and I don't want any dealings with you human lifeforms. I'm a cyborg!

Offline

#10 2008-12-06 20:33:26

okplayer02
Member
From: Denver, Colorado
Registered: 2008-11-24
Posts: 84

Re: bashrc syntax (SOLVED)

well yes that did thanks it is solved

big_smile

thanks for that last tip


Say what is good or keep silent  --Prophet Muhammad (SAW)

Offline

#11 2008-12-06 22:05:31

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: bashrc syntax (SOLVED)

Ah crap, foiled by single quotes.

On the other hand, I don't think you really need to quote $@ in this instance, so this should probably work too:

function supac {
  su -c "pacman -Rs $@"
}

Offline

#12 2008-12-06 22:11:29

bwalk
Member
Registered: 2007-03-21
Posts: 177

Re: bashrc syntax (SOLVED)

sudo?

Offline

#13 2008-12-07 00:54:11

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: bashrc syntax (SOLVED)

And if you want to error with no args:

function omgwtf() {
   if [ $# -eq 0 ]; then
      echo "usage: omgwtf <packages to remove>"
   else
      su -c "pacman -Rs $@"
   fi
}

Offline

Board footer

Powered by FluxBB