使用bash版本3.2.57(1)-release(x86_64-apple-darwin14)
如何“重新分配”或“更改”读入变量的现有值。
如果用户输入字符串IAmString
,我希望propInput
存储值iamstring
。 我只是为了举例而简单地打印到控制台。
read userInput
echo ${userInput} | tr '[:upper:]' '[:lower:]'
使用bash版本3.2.57(1)-release(x86_64-apple-darwin14)
如何“重新分配”或“更改”读入变量的现有值。
如果用户输入字符串IAmString
,我希望propInput
存储值iamstring
。 我只是为了举例而简单地打印到控制台。
read userInput
echo ${userInput} | tr '[:upper:]' '[:lower:]'
你应该存储你的命令输出:
read userInput
userInput=$(echo "$userInput" | tr '[:upper:]' '[:lower:]')
我很惊讶那个还没有起作用...
你存储值时有问题吗?
如果是这样,你需要:
userInput=$(echo ${userInput} | tr '[:upper:]' '[:lower:]')
但它看起来像是Mac环境。你得到了什么结果?
编辑,添加userInput=$()
并重新构建以更好地查询。
userInput
中。 - ROMANIA_engineeruserInput=$()
。现在正在编辑我的“评论”... - yftse