Owen_R

trying to contrive egs showing redirecting stdout (fd1) is different from writing to fd3+

Apr 22nd, 2021 (edited)
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. --
  2. - eg1.1
  3. fish code:
  4. begin
  5. if isatty 1
  6. echo "yes isatty 1"
  7. else
  8. echo "no isatty 1"
  9. end
  10. end
  11.  
  12. result:
  13. writes to terminal:
  14. yes isatty 1
  15.  
  16. - eg1.2
  17. fish code:
  18. begin
  19. if isatty 1
  20. echo "yes isatty 1"
  21. else
  22. echo "no isatty 1"
  23. end
  24. end > tempfile.txt
  25.  
  26. result:
  27. writes to file:
  28. no isatty 1
  29.  
  30. --
  31. - eg2.1
  32. fish code:
  33. begin
  34. echo "line 1"
  35. echo "line 2"
  36. echo "line 3"
  37. end > tempfile.txt
  38.  
  39. result:
  40. the file contains:
  41. line 1
  42. line 2
  43. line 3
  44.  
  45.  
  46. - eg2.2
  47. fish code:
  48. begin
  49. echo "line 1"
  50. echo "line 2" > /dev/stdout
  51. echo "line 3"
  52. end > tempfile.txt
  53.  
  54. result:
  55. to the terminal gets written:
  56. line 2
  57.  
  58. and the file contains:
  59. line 1
  60. line 3
  61.  
  62. --
  63. - eg3.1
  64. fish code:
  65. begin
  66. ls
  67. end > tempfile.txt
  68.  
  69. result:
  70. this was run in a dir containing two files:
  71. f1
  72. f2
  73. the file tempfile.txt ended up containing:
  74. f1
  75. f2
  76. tempfile.txt
  77.  
  78.  
  79. - eg3.2
  80. fish code:
  81. begin
  82. ls > /dev/stdout
  83. end > tempfile.txt
  84.  
  85. result:
  86. again, run in a dir containing two files:
  87. f1
  88. f2
  89.  
  90. it wrote to the terminal:
  91. f1 f2 tempfile.txt
  92.  
  93. and the file tempfile.txt ended up being empty
  94.  
  95.  
  96. --
  97. - eg4.1
  98. fish code:
  99. if isatty 0
  100. echo yup
  101. else
  102. echo no
  103. end
  104.  
  105. result:
  106. writes to terminal:
  107. yup
  108.  
  109. - eg4.2
  110. fish code:
  111. if isatty 0
  112. echo yup
  113. else
  114. echo no
  115. end < tempfile.txt
  116.  
  117. result:
  118. writes to terminal:
  119. no
  120.  
Advertisement
Add Comment
Please, Sign In to add comment