Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Let's say I have an alias like this:

alias findip='wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//''

the output would look like this:

matthew@ubuntu:~$ findip
71.141.232.38
matthew@ubuntu:~$

So pretty simple, it finds my ip address by connecting to the website and looking for my IP address. Now, if i were to run:

tsocks wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address://' -e 's/<.*$//'

I would get an output like this:

matthew@ubuntu:~$ tsocks wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
77.247.181.162
matthew@ubuntu:~$ 

You will notice that the IP addresses are different. This is because I routed the command through tsocks, which I have configured to use tor. But if I were to run:

tsocks findip

My output would be this:

matthew@ubuntu:~$ tsocks findip
exec: 87: findip: not found
matthew@ubuntu:~$ 

My output

How do I configure my system so that the aliases created apply when I am running through tsocks?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Alias a command to itself, and end the alias with a space:

alias exec="exec "
alias sudo="sudo "
alias tsocks="tsocks "

With this, bash will automatically expand tsocks findiptsocks wget -q ...

As seen in bash's documentation:

$ help alias
alias: alias [-p] [name[=value] ... ]
    ...
    A trailing space in VALUE causes the next word to be checked for
    alias substitution when the alias is expanded.

This, however, is not related to being root (unless you were talking about sudo usage), and cannot be done at exec() syscall level (aliases are entirely internal to bash).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.