howto:redirection_tutorial

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
Last revision Both sides next revision
howto:redirection_tutorial [2015/08/08 21:03]
bill_thomson
howto:redirection_tutorial [2019/02/23 04:01]
razzed
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 56: Line 56:
  
 the ''>​ file''​ after the command alters the file descriptors belonging to the the ''>​ file''​ after the command alters the file descriptors belonging to the
-command ​foo. It changes the file descriptor ''​1''​ (''>​ file''​ is the same as+command ​''​echo''​. It changes the file descriptor ''​1''​ (''>​ file''​ is the same as
 ''​1>​file''​) so that it points to the file ''​file''​. They will look like: ''​1>​file''​) so that it points to the file ''​file''​. They will look like:
  
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.
    
  
  • howto/redirection_tutorial.txt
  • Last modified: 2019/02/23 04:49
  • by razzed