title: Change Default Group in Script
body: <p>Is it possible to change a user's default group inside a script for the duration of that script's execution?</p>
  
  <p>I need to generate files in a script that have the proper user and group but my user's primary group is not who should own the resultant output.</p>
  
  <pre><code>$ groups
  groupa groupb
  
  $ ./myscript.sh
  
  $ ls -l
  -rw-r--r-- 1 me groupa     0 Sep 17 09:42 myscript_output.txt
  </code></pre>
  
  <p>But I <em>want</em> "groupb".</p>
  
  <p><strong>myscript.sh:</strong></p>
  
  <pre><code>#!/bin/bash
  
  touch "myscript_output.txt"
  </code></pre>