MoreBash:Declare - Typing variables

From Juneday education
Jump to: navigation, search

Work in progress

This chapter is a work in progress. Remove this section when the page is production-ready.

Introduction

This chapter introduces the declare directive in bash for creating variables with some level of typing. Bash isn't strongly typed, but declare provides some level of type safety and convenience when writing scripts.

Examples

declare -a - Array declaration

Here's an example of declaring an array and looping through it:

#!/bin/bash

declare -a DIRS=(
    se/itu/game/main/
    se/itu/game/gui/
    se/itu/game/cave/
    se/itu/game/cave/init/
    se/itu/game/test/
)

for DIR in ${DIRS[@]}
do
    javac ${DIR}*.java
done

Videos

All videos in this chapter: Bash - Declaring variables

Links

External links

Chapter links

Next page contains exercises (if any) for this topic.

« PreviousBook TOCNext »