Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added array print

  • Loading branch information...
commit 5d04e0581ecf99995e5f95ca15ccfb45be5576a8 1 parent cf830ec
@wayneeseguin wayneeseguin authored
Showing with 25 additions and 3 deletions.
  1. +16 −0 bin/array/print
  2. +3 −0  bin/array/start
  3. +6 −3 bin/json/get
View
16 bin/array/print
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+set -v # Turn on verbose logging, so that the following will present a tutorial.
+
+# array(s) module api is loaded with the line 'api/array' in shell/includes.
+
+# First we declare the my_array variable that we will use, as an array ('-a')
+typeset -a my_array
+
+# Now we assign five elements into our array.
+my_array=(one two three four five)
+
+# Printing out the array at this point should show these five elements:
+# one two three four five
+array print my_array
+
View
3  bin/array/start
@@ -8,3 +8,6 @@ set -v # Turn on verbose logging, so that the following will present a tutorial.
# 1
array start
+# Note that this is mainly for script readability now. It was originally because
+# the bash shell indexes arrays from 0 and zsh indexes arrays from 1.
+
View
9 bin/json/get
@@ -8,18 +8,21 @@ set -v # Turn on verbose logging, so that the following will present a tutorial.
file write to "/tmp/apidoc.json" \
string "{\"system\": {\"hostname\": \"$(hostname)\"}}"
-json get from "/tmp/apidoc.json" string "system"
+json get from "/tmp/apidoc.json" \
+ string "system"
# The 'system' variable should now contain the list of sub keys, in this case:
# hostname
log "system: ${system}"
-json get from "/tmp/apidoc.json" string "system/hostname"
+json get from "/tmp/apidoc.json" \
+ string "system/hostname"
# The system's hostname should now be stored in the variable 'system_hostname':
log "system/hostname: ${system_hostname}"
-json get from "/tmp/apidoc.json" string "system/hostname" as "hostname"
+json get from "/tmp/apidoc.json" \
+ string "system/hostname" as "hostname"
# The system's hostname should now be stored in the variable 'hostname':
log "hostname: ${hostname}"
Please sign in to comment.
Something went wrong with that request. Please try again.