what is meant by bash?

To directly address your question: "What does [@] mean in bash?" the [@] is used in combination with an array variable to expand all elements within that array. Here are some bash/python equivalencies

Bash

# Declare array
array=("e1" "e2" "e3")

# Print array one line
echo ${array[@]}

# Iterate over array elements
for element in "${array[@]}"
do
    echo $element
done

Python

# Declare array
array=["e1", "e2", "e3"]

# Print array one line
print(array)

# Iterate over array elements
for element in array:
    print(element)

More generally though, you seem to be having trouble understanding this legacy bash script you’ve inherited. Here it is marked up with some comments.

#!/bin/bash -e
# This script uses the babel compiler to compile a list of directories
# and files. To use this script properly make sure to populate
# the 'dirs' and 'files' arrays below before running

# Manage directories/files in two arrays
dirs=("app")
files=("server.js")

# compile-dir
# Use babel to compile a direcotry and output it into the build dir
# @param <dirname>
function compile-dir {
    babel $1 --out-dir "./build/$1"
}

# compile-file
# Use babel to compile a file and output it into the build dir
# @param <filename>
function compile-file {
    babel $1 --out-dir "./build"
}

#################################
#         -- MAIN --            #
#################################

# Begin by deleting the existing build dir
rm -rf ./build

# Compile all dirs in dirs array
for dir in "${dirs[@]}"
do
    compile-dir "$dir"
done

# Compile all files in files array
for file in "${files[@]}"
do
    compile-file $file
done

# Move 'resources' and 'config' dirs into 'resources' subdir of './build'
mkdir "./build/resources"
cp -R "./resources/" "./build/"
cp -R "./config" "./build/"

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top