go_winter_work_2025/bash/train_bash/task.sh

58 lines
1.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
CpArray_Mac() {
# Оператор Присваивания
echo -n 'eval '
echo -n "$2" # Имя массива-результата
echo -n '=( ${'
echo -n "$1" # Имя исходного массива
echo -n '[@]} )'
# Все это могло бы быть объединено в одну команду.
# Это лишь вопрос стиля.
}
declare -f CopyArray # "Указатель" на функцию
CopyArray=CpArray_Mac # Оператор Присваивания
Hype()
{
# Исходный массив с именем в $1.
# (Слить с массивом, содержащим "-- Настоящий Рок-н-Ролл".)
# Вернуть результат в массиве с именем $2.
local -a TMP
local -a hype=( -- Настоящий Рок-н-Ролл )
$($CopyArray $1 TMP)
TMP=( ${TMP[@]} ${hype[@]} )
$($CopyArray TMP $2)
}
declare -a before=( Advanced Bash Scripting )
declare -a after
echo "Массив before = ${before[@]}"
Hype before after
echo "Массив after = ${after[@]}"
# Еще?
echo "Что такое ${after[@]:4:2}?"
declare -a modest=( ${after[@]:2:1} ${after[@]:3:3} )
# ---- выделение подстроки ----
echo "Массив Modest = ${modest[@]}"
# А что в массиве 'before' ?
echo "Массив Before = ${before[@]}"
exit 0