Penguin
Diff: IORedirectionNotes
EditPageHistoryDiffInfoLikePages

Differences between current version and predecessor to the previous major change of IORedirectionNotes.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 9 Last edited on Saturday, July 14, 2007 11:55:01 pm by LawrenceDoliveiro
Older page: version 8 Last edited on Friday, July 13, 2007 1:07:23 pm by BenStaz Revert
@@ -5,24 +5,25 @@
 Firstly: 
  
 *sudo echo "#TEST REPOSITORY" >> /etc/apt/sources.list 
  
-Results in a "Permission denied error". This is because sudo spawns a new subshell and doesn't get the ''>> /etc/apt/sources.list'' because it is owned by the parent shell which is you .  
-  
+results in a "Permission denied error". This is because the ''>> /etc/apt/sources.list'' redirection is processed by your shell _before_ spawning <tt>sudo</tt>, so it is trying to open the file with your (ordinary) user privileges, not root privileges
  
 Ways around this: 
  
 1) 
  
 *sudo bash -c 'echo "#TEST REPOSITORY" >> /etc/apt/sources.list' 
  
-Commands are read from string after the ''-c'' switch. 
+The shell spawned by <tt>sudo</tt> reads its command from the string after the ''-c'' switch, so the redirection is done in a process which is already running as root
  
 2) 
  
 *echo "#TEST REPO" | sudo tee -a /etc/apt/sources.list 
  
-The 'tee' command reads from standard input and the ''-a'' switch appends it to the file. 
+The 'tee' command reads from standard input and the ''-a'' switch appends it to the file. Again, the file is opened by the process spawned by <tt>sudo</tt>, which is running as root
  
 3) 
  
 *sudo tee -a /etc/apt/sources.list <<< "#TEST REPO" 
+  
+An alternative formulation of 2), using a [HereString|HereStrings].