我有以下输出
ssh-rsa aaaaaaaaaaa bbbbbbbbbbbbb cccccccccccccc ddddddddddddddddd eeeeeeeeeeeeeeee mail: [email protected]
我想删除 ssh-rsa 和邮件之间的所有空格:
所以我会得到这个结果
ssh-rsa aaaaaaaaaaabbbbbbbbbbbbbccccccccccccccdddddddddddddddddeeeeeeeeeeeeeeee mail: [email protected]
请参阅代码中提供的说明以了解它是如何完成的:
#!/bin/bash
# Input string
input="ssh-rsa aaaaaaaaaaa bbbbbbbbbbbbb cccccccccccccc ddddddddddddddddd eeeeeeeeeeeeeeee mail: [email protected]"
# Split the input into an array
IFS=' ' read -r -a array <<< "$input"
# Initialize the output with the first element
output="${array[0]} "
# Join all elements except the last two
for ((i = 1; i < ${#array[@]} - 2; i++)); do
output+="${array[i]}"
done
# Append the last two elements with a space in between
output+=" ${array[-2]} ${array[-1]}"
# Print the result
echo "$output"