2

I don't understand how different between

a. ./target <input
b. ./target <$(cat input)
c. ./target $(<input)

./target is a C program and input is a file or payload

I want to know that how are they different and are there any more techniques or method?

2
  • I'd personally just use cat input | ./target. Commented Nov 22, 2017 at 7:57
  • 3
    You indulge in UUoC — Useless use of cat, then, @SamPagenkopf: Commented Nov 22, 2017 at 8:00

1 Answer 1

2

Two of the three notations are peculiar to Bash; all three are shell notations. The programs that are run need to process the data in quite different ways.

  1. (./target <inputinput redirection): the target program needs to read standard input to get the information.

    #include <stdio.h>
    
    int main(void)
    {
        int c;
        while ((c = getchar()) != EOF)
            putchar(c);
        return 0;
    }
    
  2. (./target <$(cat input)process substitution): the target program needs to open the file name specified in a command-line argument to get the information.

    #include <stdio.h>
    
    int main(int argc, char **argv)
    {
        if (argc != 2)
        {
            fprintf(stderr, "Usage: %s file\n", argv[0]);
            return 1;
        }
        FILE *fp = fopen(argv[1], "r");
        if (fp == 0)
        {
            fprintf(stderr, "%s: failed to open file '%s' for reading\n",
                    argv[0], argv[1]);
            return 1;
        }
    
        int c;
        while ((c = getc(fp)) != EOF)
            putchar(c);
    
        fclose(fp);
        return 0;
    }
    
  3. (./target $(<input)command substitution): the target program gets the contents of the file split into words as arguments to the program, one word per argument.

    #include <stdio.h>
    
    int main(int argc, char **argv)
    {
        int count = 0;
        for (int i = 0; i < argc; i++)
        {
           count += printf(" %s", argv[i]);
           if (count > 70)
               putchar('\n'), count = 0;
        }
        return 0;
    }
    

The processing needed is quite different, therefore.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.