Skip to content

Instantly share code, notes, and snippets.

@jimratliff
jimratliff / Exemplar_pass_array_to_bash_function_without_command_substitution
Last active May 29, 2018 05:12
Example: Pass array to bash function without command substitution #bash #bash_exemplar
Context:
Pass array to function, where one or more elements of the array have embedded spaces.
Goal: Have the embedded spaces respected in the array processed by the function.
############### The script
#!/usr/bin/env bash
set -eu
function echo_passed_array() {
list_of_options=("$@")
echo "List of options [0]: ${list_of_options[0]}"
echo "List of options [1]: ${list_of_options[1]}"
@jimratliff
jimratliff / Exemplar_pass_array_to_bash_function_with_command_substitution
Last active May 29, 2018 05:13
Example: Pass array to bash function with command substitution #bash #bash_exemplar
Context:
Pass array to function, where one or more elements of the array have embedded spaces.
Moreover, script seeks a nonnumeric result from function; uses command substitution to call the function.
For the case without command substitution, see https://gist.github.com/jimratliff/ddcb5eb7e6fb184840e5dfd7e240c7ee
Goal: Have the embedded spaces respected in the array processed by the function.
############### The script
#!/usr/bin/env bash
set -eu
function echo_passed_array() {
list_of_options=("$@")
@jimratliff
jimratliff / ascii_rainbow.sh
Last active May 29, 2018 04:55
ASCII Rainbow: Script prints samples for the different ASCII color codes #bash #ASCII_colors
##########################################################################################
#!/usr/bin/env bash
#
# ANSI Rainbow
# See, e.g., "How to change the output color of echo in Linux", Stack Overflow, 5/10/2011
# https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
for (( i = 30; i < 38; i++ )); do echo -e "\033[0;"$i"m Normal: (0;$i); \033[1;"$i"m Light: (1;$i)"; done
@jimratliff
jimratliff / Example_return_multiple_values_from_bash_function_with_command_substitution_and_read.sh
Last active October 24, 2023 15:54
Example: Bash function returns multiple values, passed via command substitution, with a READ command and Here string in calling script #bash #bash_exemplar
# Example: Bash function returns multiple values, passed via command substitution,
# with a READ command and Here string in calling script
#!/usr/bin/env bash
set -e #Stop on any errors
function inside_function() {
yvariable1="8"
yvariable2="64"
echo $yvariable1 $yvariable2
}
@jimratliff
jimratliff / Empirical_test_bash_variable_scope_within_nested_functions.sh
Last active May 29, 2018 04:56
Empirical test of bash variable scope: main calls function, which calls deeper function #bash
##########################################################################################
#!/usr/bin/env bash
#
# Script to determine empirically the extent to which a variable set in a script or
# function can be seen by a hierarchically related function or script
# Specifically, (a) main script calls (b) function level1(), which calls
# function level2(). (No arguments are used in any function call.)
# Scalar variables are set in each component prior to any function call:
# Main script sets $set_in_main_x, for x ∈ {A,B,C}
# Function level1() sets $set_in_level_1_x, for x ∈ {A,B,C}
@jimratliff
jimratliff / man.plutil.high_sierra
Last active May 29, 2018 04:27
plutil man page, High Sierra #dotfiles
# See also the help for plutil, which discloses additional options not disclosed in the man page
# For the help content, see https://gist.github.com/jimratliff/71414b2896e1b5feb40038ce688205de
PLUTIL(1) BSD General Commands Manual PLUTIL(1)
NAME
plutil -- property list utility
SYNOPSIS
@jimratliff
jimratliff / man.PlistBuddy.High_Sierra
Last active August 18, 2021 08:38
PlistBuddy man page, High Sierra #dotfiles
PLISTBUDDY(8) BSD System Manager's Manual PLISTBUDDY(8)
NAME
PlistBuddy -- read and write values to plists
SYNOPSIS
PlistBuddy [-cxh] file.plist
DESCRIPTION
The PlistBuddy command is used to read and modify values inside of a
@jimratliff
jimratliff / help.plutil.High_Sierra
Last active May 29, 2018 04:28
plutil help (High Sierra) #dotfiles
# This help for plutil discloses additional options not disclosed in the man page
# For the man page, see https://gist.github.com/jimratliff/daeba692a66d2683b35d193e08b800b0
$ plutil -help
plutil: [command_option] [other_options] file...
The file '-' means stdin
Command options are (-lint is the default):
-help show this message and exit
-lint check the property list files for syntax errors
-convert fmt rewrite property list files in format
@jimratliff
jimratliff / Mac_keyboard_ASCII_and_virtual_keys.tsv
Last active May 1, 2024 13:27
ASCII and Mac Virtual Key codes for editing com.apple.symbolichotkeys plist. (See sources/information in first comment.) #dotfiles #character_codes #symbolichotkeys
Keyboard Label Character ASCII code (Parameter #1) Mac Virtual Key Code (Parameter #2) Layout dependence?
0 0 48 029 ANSI-US
1 1 49 018 ANSI-US
2 2 50 019 ANSI-US
3 3 51 020 ANSI-US
4 4 52 021 ANSI-US
5 5 53 023 ANSI-US
6 6 54 022 ANSI-US
7 7 55 026 ANSI-US
@jimratliff
jimratliff / pristine.symbolichotkeys.txt
Last active May 29, 2018 04:26
Pristine defaults read com.apple.symbolichotkeys (High Sierra) #dotfiles #symbolichotkeys
Last login: Sun Apr 22 10:04:40 on ttys001
Primary-MBPR:~ playground1$ defaults read com.apple.symbolichotkeys
{
AppleSymbolicHotKeys = {
15 = {
enabled = 0;
};
16 = {
enabled = 0;
};