Per Erik Strandberg /cv /kurser /blog

What is @ doing in the Console?

Something really strange is afoot in the Arctic.

If you are not familiar with ff (filefetcher) and dog (DOG: the cat-killer) please take a look at [1] and [2]

The example below shows what happens when I use cat and dog on a file containing a list of files:

First we build a list of files in the file c_files.txt.

C:\temp>ff *.c
C:\temp\c_hello.c
C:\temp\fulc.c
C:\temp\hello.c
C:\temp\indent.c
C:\temp\minimal.c
C:\temp\oneliner.c
C:\temp\quine.c
C:\temp\sleep.c

C:\temp>ff *.c > c_files.txt

Now we try to print the contents of the file c_files.txt on the console.

C:\temp>dog c_files.txt
C:\temp\c_hello.c
C:\temp\fulc.c
C:\temp\hello.c
C:\temp\indent.c
C:\temp\minimal.c
C:\temp\oneliner.c
C:\temp\quine.c
C:\temp\sleep.c

C:\temp>type c_files.txt
C:\temp\c_hello.c
C:\temp\fulc.c
C:\temp\hello.c
C:\temp\indent.c
C:\temp\minimal.c
C:\temp\oneliner.c
C:\temp\quine.c
C:\temp\sleep.c

C:\temp>cat c_files.txt
C:\temp\c_hello.c
C:\temp\fulc.c
C:\temp\hello.c
C:\temp\indent.c
C:\temp\minimal.c
C:\temp\oneliner.c
C:\temp\quine.c
C:\temp\sleep.c

That went as planned - now let's try to do the same thing with a @.

C:\temp>dog @c_files.txt
DOG> No files found.

C:\temp>type @c_files.txt
The system cannot find the file specified.

C:\temp>cat @c_files.txt
#include <stdio.h>

void main(int argc, char * argv[])
{
  int i = 0;
        for(i=0; i < argc; i++)
          printf("argv[%d]: '%s'\n",i,argv[i]);
}
#include <stdio.h>
// <snip>

As you can see cat is clever, or stupid, here - instead of being mad that no filenames matched the pattern it prints the contents of the files in the list.

Fun, right?


This page belongs to Kategori Programmering.