【发布时间】:2020-05-30 09:05:59
【问题描述】:
我寻找一种方法来将一个数组中的键与另一个数组进行转换。
tmp_title=$3
title=$(echo ${tmp_title,,} | sed -e 's/\s/-/g')
tags=(computer media state society)
de=(computer medien staat gesellschaft)
fr=(ordinateur journalisme politique société)
ru=(Компьютер СМИ штат общество)
file="./content/de/blog/$(date +"%Y")/$(date +"%m")/$title.md"
if test -n "$2"; then
# check tag is in tags array
if [[ ${tags[*]} =~ $2 ]]; then
# check the folder structure is right
if [[ -d ./content/de/blog/$(date +"%Y")/$(date +"%m") ]]; then
# create the content and fill up the file
echo "---" >> "$file"
echo "title: \"$3\"" >> "$file"
echo "date: $(date +\"%Y-%m-%d\")" >> "$file"
echo "draft: false" >> "$file"
echo "tags: \"$2\"" >> "$file"
echo "shorttext:" >> "$file"
echo "cover: \"$2\"" >> "$file"
echo "lang: $1" >> "$file"
echo "---" >> "$file"
fi
else
echo "Enter a valid tag name ..."
fi
fi
我寻找一种方法来翻译语言数组值中的 "tags: \"$2\"" >> "$file"。当我将社会附加到脚本时,应该是标签:“gesellschaft”。
感谢您的帮助。
西尔维奥
【问题讨论】:
标签: arrays bash shell arraylist indexof