문제

Suppose I have a file named "file1". I want to display the contents of "file1" using the cat command in Unix.

Both cat file1 and cat < file1 are working similarly. What is the difference between them?

도움이 되었습니까?

해결책

It's where input comes from.

  • If you say cat file1 the shell doesn't do anything special. cat calls open(2) on the file and reads from it
  • If you say cat < file1 the shell calls open(2) on the file and calls dup(2) into STDIN_FILENO for cat. cat just reads from STDIN_FILENO

다른 팁

We can use another command to notice the difference between:

wc –w food2.txt 

Possible output:

6 food2.txt 

the command tells the file name since it knows it (passed as an argument) .

wc –w < food2.txt 

Possible output:

6 

the standard input is redirected to file food2.txt without the command knowing about it .

cat opens a file, and cat > fileName tells the shell to open the file in the cat standard input.

Here is a link with more detailed information/answer: https://unix.stackexchange.com/questions/258931/difference-between-cat-and-cat

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top