简体   繁体   English

我需要打印行号以及用户提示的内容,怎么做? 我尝试了以下代码,但它不起作用

[英]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.

相关问题 我需要打印行号以及用户提示的内容,怎么做? - I need to print the line number along with the content prompting from user, How to do that? 我需要加载一些模块,但是除非更改bash配置文件,否则加载模块在我的环境中不起作用。 如何在tcsh中执行此操作? - I need to load some modules but load module doesn't work in my environment unless I change the bash profile. How do I do this in tcsh? 如何在Linux命令行上预替换以下内容 - How do I preg replace the following at linux command line 如何在文件中添加行号? - How do I add a line number to a file? Linux:在Linux中使用AWK,当制表符分隔文件的值不匹配时,如何打印行号和列号 - Linux : How can I print line number and column number when values do not match for tab separated files using AWK in linux 我需要在一行中打印多个打印结果 - I need multiple print result in one line 我需要重写这一行代码,并且需要帮助 - I need to rewrite this line of code, and need help 如果我在其中输入退出代码,则脚本不起作用 - script doesn't work if i put an exit code in it 如何在linux中打印另一个用户的当前工作目录? - How do I print the current working directory of another user in linux? Content-Type在线命令在Centos 6.5上不起作用 - Content-Type on line command doesn't work on Centos 6.5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM