我正在寻找一种将键从一个数组转换为另一个数组的方法。
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”。
谢谢您的帮助。
西尔维奥
考虑此方法
case $LANG in
*en*) tags=(computer media state society );;
*de*) tags=(computer medien staat gesellschaft);;
*fr*) tags=(ordinateur journalisme politique société );;
*ru*) tags=(Компьютер СМИ штат общество );;
esac