我有一个文本文件,其中填充了以下示例值:
1:0:0:Monitoring stuff with Zabbix/OCS:24 HOURS
所以我想用一个变量更改第二个字段。我正在尝试这样做:
#!/bin/bash
PRIOR="Priority = 1 - Must have | 2 - Nice to have | 3 - Interesting | 0 - Not interesting"
while read -r line;
do
echo $line
echo $PRIOR
echo -n "Set your priority: "
read SETP</dev/tty
echo "Priority defined: "$SETP
<change my 2nd column value with $SETP>
done < courses.txt
这是一种方法
newline=$( echo "$line" | sed "s/:[^:]\+/:$SETP/")
它将用冒号和用户输入替换第一个冒号,后跟非冒号字符。
一些代码审查说明:
read PATH
,然后想知道为什么脚本损坏了。
priorities="..."
,read setp
等echo "$line"
echo "Priority defined: $setp"
-引号内的变量if [[ $setp == *[^0-9]* ]]; then echo "digits only! try again"; fi
read -p "Set your priority: " setp < /dev/tty
-不需要单独的echo语句本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句