User Tools

Site Tools


unix_102

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
unix_102 [2016/06/07 13:51]
peek [Playing Around]
unix_102 [2016/06/07 13:57] (current)
peek
Line 359: Line 359:
 ^ Get a text file to play around with || ^ Get a text file to play around with ||
 ^ Type: | <code>$ wget -O file.txt 'http://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt' ^ Type: | <code>$ wget -O file.txt 'http://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt'
---2016-06-07 09:25:57--  http://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt+--2016-06-07 09:25:57--  http://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespea 
 +re.txt
 Resolving ocw.mit.edu (ocw.mit.edu)... 23.15.135.8, 23.15.135.19 Resolving ocw.mit.edu (ocw.mit.edu)... 23.15.135.8, 23.15.135.19
 Connecting to ocw.mit.edu (ocw.mit.edu)|23.15.135.8|:80... connected. Connecting to ocw.mit.edu (ocw.mit.edu)|23.15.135.8|:80... connected.
Line 422: Line 423:
 9081 you 9081 you
 </code> | </code> |
 +^ NOTE: How would you know to do that!?!?  The easiest way is to just search online for someone who's already done it, and then copy what they typed.  There are several online forums for command line usage too.  That's what I did.  Awk is so powerful, I've only scratched the surface of it myself. ||
 ^ In the file '/etc/passwd', what is the 8th line? || ^ In the file '/etc/passwd', what is the 8th line? ||
 ^ Type: | <code>$ cat /etc/passwd | head -8 | tail -1 ^ Type: | <code>$ cat /etc/passwd | head -8 | tail -1
Line 438: Line 440:
 0 0
 </code> | </code> |
-^ NOTE: That didn't work!  Why?  Because the while loop executes in a subshell, and while it is possible to pass values of exported values from parent shell to child subshell, the child gets a copy and not the original variable.  This means that when the child process sums up values for 'n', that value is lost when the child process exits.  Since the parent's version of 'n' never changes, it's value is still zero. ||+NOTE: That didn't work!  Why?  Because the while loop executes in a subshell, and while it is possible to pass values of exported values from parent shell to child subshell, the child gets a copy and not the original variable.  This means that when the child process sums up values for 'n', that value is lost when the child process exits.  Since the parent's version of 'n' never changes, it's value is still zero. |
 ^ So what's the correct way to do it?  Here's one way that works: || ^ So what's the correct way to do it?  Here's one way that works: ||
 ^ Type: | <code>$ n=0 ^ Type: | <code>$ n=0
Line 447: Line 449:
 68740 68740
 </code> | </code> |
-^ NOTE: The for loop doesn't execute in a subshell.  How would you know this?  Well, reading the bash manual is probably the best way.  :-/ ||+NOTE: The for loop doesn't execute in a subshell.  How would you know this?  Well, reading the bash manual is probably the best way.  :-/ |
unix_102.1465307484.txt.gz · Last modified: 2016/06/07 13:51 by peek