Skip to content

Instantly share code, notes, and snippets.

View DanielSmon's full-sized avatar

Daniel Šmon DanielSmon

  • Brisbane, Australia
  • 14:36 (UTC +10:00)
View GitHub Profile
@DanielSmon
DanielSmon / Script Name.cmd
Created March 10, 2021 07:00
PowerShell launch cmd
@ECHO OFF
REM Rename this file to be the same name as your PowerShell .ps1 script.
REM This script must be in the same directory as your .ps1 script.
PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -Command ""& {%~dpn0.ps1;pause}""' -Verb RunAs}"
@DanielSmon
DanielSmon / backup-drive.cmd
Created March 15, 2021 01:29
backup-drive.cmd
@ECHO OFF
IF X%1==X GOTO INVALID_ARGS
IF X%2==X GOTO INVALID_ARGS
GOTO:RUN
:INVALID_ARGS
ECHO Invalid arguments
ECHO.
@DanielSmon
DanielSmon / bash-argument-parsing.sh
Created May 11, 2024 08:06
Bash argument parsing example
#!/bin/bash
set -o errexit # Fail and exit the script immediately if any command fails
set -o nounset # Throw an error if there are unset variables
# Parse arguments (based on https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash)
HARD="false"
VERBOSE="false"
usage_error () { echo >&2 "$(basename ${0}): ${1}"; exit 2; }
assert_argument () { test "${1}" != "${EOL}" || usage_error "${2} requires an argument"; } # TODO: Force boolean