面试题答案
一键面试#!/bin/bash
str="a3bcd &12# 456 efg!h"
words=($str)
result=""
for word in "${words[@]}"; do
if [[ $word =~ ^[[:digit:][:punct:]]+$ ]]; then
result="$result $word"
else
sorted_word=$(echo $word | sed 's/[^a-zA-Z]//g' | tr -d '\n' | sort | uniq | tr -d '\n')
for char in $word; do
if [[ $char =~ [a-zA-Z] ]]; then
continue
fi
sorted_word="$sorted_word$char"
done
result="$result $sorted_word"
fi
done
echo "${result:1}"