shell 字符串分割
#!/bin/bash
url="https://github.com/AntsCodeCommunity/------------/https://blog.youkuaiyun.com/AntsCode"
echo "~~~~~~ONE~~~~~~"
mapfile -d " " -t array_str_o <<< "${url//\// }"
for str in "${array_str_o[@]}"
do
echo "${str}"
done
echo "~~~~~~TWO~~~~~~"
OLD_IFS=${IFS}
IFS="/"
for str in ${url}
do
echo "${str}"
done
echo "~~~~~~THREE~~~~~~"
OLD_IFS=${IFS}
IFS="/" read -r -a array_str_t <<< ${url}
for str in "${array_str_t[@]}"
do
echo "${str}"
done
IFS=${OLD_IFS}
echo "~~~~~~FOUR~~~~~~"
mapfile -d " " -t array_str_f <<< "$(echo ${url} | tr '/' ' ')"
for str in "${array_str_f[@]}"
do
echo "${str}"
done
echo "~~~~~~END~~~~~~"