Files
GoogleDriveManagement/wiki/Command-Line-Parsing.md
Ross Scroggs 9349bc413d
Some checks failed
Push wiki / pushwiki (push) Has been cancelled
Build and test GAM / build (false, build, 1, Build Intel Ubuntu Jammy, ubuntu-22.04) (push) Has been cancelled
Build and test GAM / build (false, build, 10, Build x86_64 macOS 15, macos-15-intel) (push) Has been cancelled
Build and test GAM / build (false, build, 11, Build Arm MacOS 26, macos-26) (push) Has been cancelled
Build and test GAM / build (false, build, 12, Build Intel Windows, windows-2025) (push) Has been cancelled
Build and test GAM / build (false, build, 13, Build Arm Windows, windows-11-arm) (push) Has been cancelled
Build and test GAM / build (false, build, 2, Build Intel Ubuntu Noble, ubuntu-24.04) (push) Has been cancelled
Build and test GAM / build (false, build, 3, Build Arm Ubuntu Noble, ubuntu-24.04-arm) (push) Has been cancelled
Build and test GAM / build (false, build, 4, Build Arm Ubuntu Jammy, ubuntu-22.04-arm) (push) Has been cancelled
Build and test GAM / build (false, build, 5, Build Intel StaticX Legacy, ubuntu-22.04, yes) (push) Has been cancelled
Build and test GAM / build (false, build, 6, Build Arm StaticX Legacy, ubuntu-22.04-arm, yes) (push) Has been cancelled
Build and test GAM / build (false, build, 8, Build Arm MacOS 14, macos-14) (push) Has been cancelled
Build and test GAM / build (false, build, 9, Build Arm MacOS 15, macos-15) (push) Has been cancelled
Build and test GAM / build (false, test, 14, Test Python 3.10, ubuntu-24.04, 3.10) (push) Has been cancelled
Build and test GAM / build (false, test, 15, Test Python 3.11, ubuntu-24.04, 3.11) (push) Has been cancelled
Build and test GAM / build (false, test, 16, Test Python 3.12, ubuntu-24.04, 3.12) (push) Has been cancelled
Build and test GAM / build (false, test, 17, Test Python 3.15-dev, ubuntu-24.04, 3.15-dev) (push) Has been cancelled
Build and test GAM / build (true, test, 18, Test Python 3.14 freethread, ubuntu-24.04, 3.14) (push) Has been cancelled
Build and test GAM / merge (push) Has been cancelled
Build and test GAM / publish (push) Has been cancelled
Check for Google Root CA Updates / check-certs (push) Has been cancelled
Update Command-Line-Parsing.md
2025-11-04 19:44:35 -08:00

4.3 KiB

Command Line Parsing

Linux and MacOS

When entering gam csv commands, you should enclose references to CSV file headers in "; e.g., name "~name".

In bash, if an argument contains a ~, |, >, or <, you must enclose the argument in "; e.g., name "Test|Group".

In zsh, if an argument contains a ~, |, !, >, or <, you must enclose the argument in '; e.g., name 'Test|Group'.

To embed a ' in a string enclosed in ", enter '; name "Test'Group".

To embed a " in a string enclosed in ', enter "; name 'Test"Group'.

To embed a ' in a string enclosed in ', enter '\''; name 'Test'\''Group'.

To embed a " in a string enclosed in ", enter \"; name "Test\"Group".

Linux and MacOS do not recognize smart or curly quotes, and , they can not be used to enclose arguments.

Windows Command Prompt

Command Prompt does not recognize smart or curly quotes, and , they can not be used to enclose arguments.

Command Prompt does not recognize single quotes, ', they can not be used to enclose arguments.

To embed a ' in a string enclosed in ", enter '; name "Test'Group".

To embed a " in a string enclosed in ", enter \"; name "Test\"Group".

Windows PowerShell

In PowerShell, if you want an empty string argument, you must enter: `"`"

PowerShell does not recognize smart or curly quotes, and , they can not be used to enclose arguments.

To embed a ' in a string enclosed in ", enter '; name "Test'Group".

To embed a " in a string enclosed in ", enter `"; name "Test`"Group".

To embed a ' in a string enclosed in ', enter ''; name 'Test''Group'.

To embed a " in a string enclosed in ', enter \"; name 'Test\"Group'.

List quoting rules

Items in a list can be separated by commas or spaces; if an item itself contains a comma, a space or a single quote, special quoting must be used. Typically, you will enclose the entire list in double quotes and quote each item in the list as detailed below.

  • Items, separated by commas, without spaces, commas or single quotes in the items themselves
    • "item,item,item"
  • Items, separated by spaces, without spaces, commas or single quotes in the items themselves
    • "item item item"
  • Items, separated by commas, with spaces, commas or single quotes in the items themselves
    • "'it em','it,em',\"it'em\"" - Linux, MacOS, Windows Command Prompt
    • "'it\ em','it,em',`"it\'em`"" - Windows Power Shell
  • Items, separated by spaces, with spaces, commas or single quotes in the items themselves
    • "'it em' 'it,em' \"it'em\"" - Linux, MacOS, Windows Command Prompt
    • "'it\ em' 'it,em' `"it\'em`"" - Windows Power Shell

Typical places where these rules apply are lists of OUs and Contact Groups.

Queries example

Linux and MacOS

gam print users queries "\"orgUnitPath='/Students/Lower School/2027'\",\"orgUnitPath='/Students/Lower School/2028'\""

Windows Command Prompt

gam print users queries "\"orgUnitPath='/Students/Lower School/2027'\",\"orgUnitPath='/Students/Lower School/2028'\""

Windows Power Shell

gam print users queries "`"orgUnitPath=\'/Students/Lower\ School/2027\'`",`"orgUnitPath=\'/Students/Lower\ School/2028\'`""

Capture command output

To retrieve an item count with showitemcountonly:

Linux/MacOS
count=$(gam print users query "orgUnitPath='/Students/Middle School'" showitemcountonly)
Windows PowerShell
$count = & gam print users query "orgUnitPath='/Students/Middle School'" showitemcountonly
Windows Command Prompt
for /f "delims=" %a in ('gam print users query "orgUnitPath='/Students/Middle School'" showitemcountonly') do set count=%a

To retrieve a File/Shared Drive ID with returnidonly:

Linux/MacOS
itemId=$(gam user user@domain.com create shareddrive|drivefile ... returnidonly)
Windows PowerShell
$itemId = & gam user user@domain.com create shareddrive|drivefile ... returnidonly
Windows Command Prompt
for /f "delims=" %a in ('gam user user@domain.com create shareddrive|drivefile ... returnidonly') do set itemId=%a