Puede hacer que la falla sea predeterminada, pero coloque una condición de que el código solo se ejecute si se cumple la condición
#!/bin/bash
input='foo'
var='1'
case $input in
foo)
echo "Do fall through"
;& #always fall through
*)
if [ $var = "1" ] #execute only if condition matches
then
echo "fallthrough took place"
fi
esac
Pero como sugirió ilkkachu, también puedes usar condiciones en lugar de cambiar.
Я думаю, вы могли бы также просто использовать пару синтаксисов Bash Parameter Expansion .
Главное было бы:
# Use a '_' as IFS value to concatenate arguments while expanding them
IFS=_
# Expand all arguments as "$*", removing their suffix if it matches ".txt"
names="${*%.txt}"
# Provide all arguments as "$@" to a `cat`, redirected to
# a file named as the concatenated names made uppercase
cat "${@?}" > "${names^^?}.txt"
# The ${@?} syntax prints an error if you don't provide arguments
Можно использовать как один -вкладыш, как в:
bash -c 'IFS=_ names="${*%.txt}"; cat "${@?}" "${names^^?}.txt"' joiner USA.txt Florida.txt Miami.txt
Или сделал функцию:
joiner () {
local IFS=_
names="${*%.txt}"
cat "${@?}" > "${names^^?}.txt"
}
для включения в сценарий или source
для редактирования из вашей интерактивной оболочки, а затем для использования так же, как в:
joiner USA.txt Florida.txt Miami.txt
грязно, но работает:
#!/bin/bash
files="$@"
new_file=()
function join_by { local IFS="$1"; shift; echo "$*"; }
for file in $files; do
prefix=$(echo $file | awk -F'.' '{print $1}')
new_file+=( $prefix )
cat $file >> temp_file.txt
done
new_name=$(join_by _ "${new_file[@]}")
mv temp_file.txt $new_name.txt
запустите его с помощью
bash script_name.sh file.txt file2.txt file3.txt...
он объединит файлы и создаст имя файла на основе заданных файлов.