title: Run bash script with sudo but create files with user as owner
body: <p>I have a bash script, create-file.sh, that creates a file named a:</p>
  
  <pre><code>   $ cat create-file.sh
     # /bin/bash
     touch a
  </code></pre>
  
  <p>When I run the script it creates a file 'a' with my user as owner.</p>
  
  <pre><code> $ ./create-file.sh
   $ ls -l
   -rw-r--r--  1 shai  wheel  0 Aug 16 17:19 a
  </code></pre>
  
  <p>However when I run the script under sudo the file is created with root as user:</p>
  
  <pre><code> $ sudo ./create-file.sh
   $ ls -l
   -rw-r--r--  1 root  wheel  0 Aug 16 17:19 a
  </code></pre>
  
  <p>Is there a way to tell a script that runs under sudo to create the file with my user as owner?</p>
  
  <ul>
  <li>you would be correct to say that a script that touches a single file does not need to run under sudo. This example is of course  a reduction of the original problem, my script has much more and does need to run under sudo, but I still want the files to be created with my user as owner. </li>
  </ul>