[英]I need to print the line number along with the content prompting from user, How to do that? I tried this following code but it doesn't work
Even if the line number is more than the present content it has to display the line numbers for empty lines and then print the user input in the specified line number with the content.即使行号多于当前内容,它也必须显示空行的行号,然后在指定的行号中打印用户输入的内容。
#!/bin/bash
file2='file2.txt'
echo -en "Enter the line number:"
read line_number
echo -en "Enter the name of the city:"
read city_name
total= 0
if [ "$line_number" > "$total" ]
then
awk -v city_name="$city_name" -v line_no="$line_no" -F, {print
city_name} 1' "file2"
fi
Use -lt/-gt
instead of '</>'使用
-lt/-gt
代替 '</>'
>>> x=7
>>> y=99
>>> if [ $x < $y ] ; then echo "x < y"; else echo "x >= y" ; fi
x >= y
>>> if [[ $x -lt $y ]] ; then echo "x < y"; else echo "x >= y" ; fi
x < y
Or use double [[]]
或使用双
[[]]
>>> if [[ $x < $y ]] ; then echo "x < y"; else echo "x >= y" ; fi
x < y
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.