Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
howto:redirection_tutorial [2015/08/08 23:03]
bill_thomson
howto:redirection_tutorial [2017/02/04 21:55] (current)
twc [stdin, stdout, stderr] - change lsof pseudo terminal number to match that referenced in the rest of the page
Line 21: Line 21:
 # lsof +f g -ap $BASHPID -d 0,1,2 # lsof +f g -ap $BASHPID -d 0,1,2
 COMMAND ​  PID USER   ​FD ​  TYPE FILE-FLAG DEVICE SIZE/OFF NODE NAME COMMAND ​  PID USER   ​FD ​  TYPE FILE-FLAG DEVICE SIZE/OFF NODE NAME
-bash    12135 root    0u   ​CHR ​    RW,LG 136,​13 ​     0t0   16 /dev/pts/13 +bash    12135 root    0u   ​CHR ​    RW,LG 136,​13 ​     0t0   16 /dev/pts/5 
-bash    12135 root    1u   ​CHR ​    RW,LG 136,​13 ​     0t0   16 /dev/pts/13 +bash    12135 root    1u   ​CHR ​    RW,LG 136,​13 ​     0t0   16 /dev/pts/5 
-bash    12135 root    2u   ​CHR ​    RW,LG 136,​13 ​     0t0   16 /dev/pts/13+bash    12135 root    2u   ​CHR ​    RW,LG 136,​13 ​     0t0   16 /dev/pts/5
 </​code>​ </​code>​
  
Line 391: Line 391:
 <​code>​ <​code>​
  exec 3<file  exec 3<file
- while read -u 3 line;​do ​echo echo "​$line";​ read -p "Press any key" -n 1;done+ while read -u 3 line;do echo "​$line";​ read -p "Press any key" -n 1;done
 </​code>​ </​code>​
  
Line 606: Line 606:
  
 I used to have trouble choosing between ''​0&<​3''​ ''​3&>​1''​ ''​3>&​1''​ ''<​nowiki>​->​2</​nowiki>''​ ''​-<&​0''​ ''&​-<​0''​ I used to have trouble choosing between ''​0&<​3''​ ''​3&>​1''​ ''​3>&​1''​ ''<​nowiki>​->​2</​nowiki>''​ ''​-<&​0''​ ''&​-<​0''​
-''​0<&​-''​ etc... (I think probably because the syntax ​represents ​more the result, i.e., the redirection,​ than+''​0<&​-''​ etc... (I think probably because the syntax ​is more representative of the result, i.e., the redirection,​ than
 what is done, i.e., opening, closing, or duplicating file descriptors). what is done, i.e., opening, closing, or duplicating file descriptors).
  
Line 617: Line 617:
  
   * ''​lhs''​ is always a file description,​ i.e., a number:   * ''​lhs''​ is always a file description,​ i.e., a number:
-    * Either ​one we want to open, duplicate, move or one we want to close. If the op is ''<''​ then there is an implicit 0, if it's ''>''​ or ''<​nowiki>>></​nowiki>'',​ there is an implicit 1.+    * Either we want to open, duplicate, move or we want to close. If the op is ''<''​ then there is an implicit 0, if it's ''>''​ or ''<​nowiki>>></​nowiki>'',​ there is an implicit 1.
  
  
-  * ''​op''​ is either ​''<'',​ ''>'',​ ''<​nowiki>>></​nowiki>'',​ ''>​|'',​ or ''<>'':​ +  * ''​op''​ is ''<'',​ ''>'',​ ''<​nowiki>>></​nowiki>'',​ ''>​|'',​ or ''<>'':​ 
-    * ''<''​ if the file decriptor in ''​lhs''​ will be read, ''>''​ if it will be written, ''<​nowiki>>></​nowiki>''​ if data will be appended to the file, ''>​|''​ to overwrite an existing file  or ''<>''​ if it will be both read and written.+    * ''<''​ if the file decriptor in ''​lhs''​ will be read, ''>''​ if it will be written, ''<​nowiki>>></​nowiki>''​ if data is to be appended to the file, ''>​|''​ to overwrite an existing file  or ''<>''​ if it will be both read and written.
  
  
   * ''​rhs''​ is the thing that the file descriptor will describe:   * ''​rhs''​ is the thing that the file descriptor will describe:
-    * It can be either ​the name of a file, the place where another descriptor goes (''&​1''​),​ or the special nowhere, ''&​-'',​ which will close the file descriptor.+    * It can be the name of a file, the place where another descriptor goes (''&​1''​),​ or, ''&​-'',​ which will close the file descriptor.