loxaxs
loxaxs

Reputation: 2289

Bash, [.bashrc] a function for an alias

[In my .bashrc]

Basically I try to make an alias:

alias e='su -c'

But when I write in a terminal:

~$ e ls -goFha /root 

I (obviously) get the error:

su: group oFha does not exist

If $str were replaced by the rest of the command, the herebelow code would work:

alias e='su -c "$str"'

But alias don't work this way. Therefore, I thought to a function.

Replacing $str by the whole argument string, it could be something like:

e () {
  "su -c '$str'"
}

How to get the whole argument string in a function?

How would you write my function?

Thanks

Upvotes: 1

Views: 262

Answers (2)

Jair López
Jair López

Reputation: 650

Here is another solution:

e() { 
   su -c "$*"
}

Upvotes: 3

Christos Papoulas
Christos Papoulas

Reputation: 2578

You can try this:


    e () {
      CMD="$@"
      su -c "$CMD"
    }

Upvotes: 1

Related Questions