sh - 按分隔符拆分字符串 [英] sh - split string by delimiter
本文介绍了sh - 按分隔符拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
s='id;some text here with possible ; inside'
IFS=';' read -r id string <<< "$s"
echo "$id"
错误
restore.sh: 2: restore.sh: Syntax error: redirection unexpected
bash 版本 GNU bash,版本 4.2.37(1)-release (x86_64-pc-linux-gnu)
推荐答案
您似乎在使用 sh
来执行脚本.sh
不支持这里字符串;因此错误.
You seem to be using sh
to execute the script. Herestrings aren't supported in sh
; hence the error.
确保您使用 bash
来执行脚本.
Ensure that you're using bash
to execute the script.
这篇关于sh - 按分隔符拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文