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:~$
How do I configure my system so that the aliases created apply when I am running through tsocks?
答案1
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 findip
→ tsocks 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
).