|
CS469/569 - Linux and Unix Administration and Networking
Spring 2022
|
Displaying ./code/02-01-Bash2/data-types.sh
#!/bin/bash
# This is a comment
# By default all variables are strings:
# You may not have any spaces before or after the =, in fact the entire variable
# definition must be exactly one word.
echo "Strings:"
var=foobar
var2="foobar"
# Strings with spaces must be quoted:
var3="foo bar baz"
start=0
length=3
echo "$var or ${var}"
echo "${#var} is the length of the string"
echo "64 bit integers"
let num=0
declare -i num=42
echo "arrays"
var=( a b c )
declare -a var=(a b c)
declare -a foo
foo[0]=a
foo[1]=b
foo[2]=c
echo "${foo[x]} is value x in foo"
echo "${foo[*]} is all the values in foo"
echo "${#foo[*]} is the number of values in foo"
echo "Associative arrays:"
# Must declare an associative array with 'declare -A' before using:
declare -A foo
foo[bar]=baz
foo[one]=1
foo[two]=2
|