0

Suppose command1 takes another command (say command2) as argument, with command2's arguments as the remaining arguments of comman1, i.e.

command1 command2 arg...

When command2 is a made up of several commands (each of which might have its own arguments and options), e.g. when command2 is command 3; command 4 and command 3 | command 4, how do you specify command2 as an argument to command1?

Does my question belong to bash, command1, or both?

  1. The solution I can think of is: writing command2 as a bash script and passing the script name in place of command2 as an argument to command1.

    But it seems not work in the following example:

    $ torify /tmp/test-tor/download.sh
    /usr/bin/torsocks: 162: exec: /tmp/test-tor/download.sh: not found
    

    where the content of /tmp/test-tor/download.sh is:

    #! /usr/bin/bash
    
    curl ifconfig.me 
    myprogram -n myarg
    
  2. I also would like to know if it is possible to solve the problem without writing a script, because it seems overkill to write a script when command2 is short.

    For example, when using tor with a program, I want to check my external ip address by curl ifconfig.me, before running the program

    torify "curl ifconfig.me; myprogram -n myarg" 
    

    but it doesn't work.

  • searching for torify using google is bringing up tor project related web pages. I am pretty sure there is a large user comunity behind the tor project and at least a few discussion boards and/or mailing lists. Did you try asking this question there. Because, if your script is there and torify is telling you it can not find it, this might be because of the default behavior of tor, not necessarily bash. – MelBurslan Apr 10 '16 at 4:54
  • it seems that torify is a wrappter of torsocks, which is in turn a wrapper of tor. – Tim Apr 10 '16 at 4:55
  • Yeah, and I remember a lot of nastiness going about tor, like people's real addresses being discovered and such not too long time ago. This behavior of tor might be intentional. You might need to tweak it a little. I am by no means a tor user or know anything about it. Hence, can't be much help. – MelBurslan Apr 10 '16 at 5:01
1

[The following links may not be the actual version you have, but are probably similar enough]. The torify command is a shell script, which just calls torsocks which is another shell script that just does exec.

So you should just be able to provide multiple commands to torify like this:

torify sh -c 'curl ifconfig.me; myprogram -n myarg'

The problem you have with torify /tmp/test-tor/download.sh is probably that the script you wrote should start with #!/bin/bash; some systems don't have a /usr/bin/bash. Make sure you chmod +x your script too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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