【问题标题】:User input choice with either head or tail command使用 head 或 tail 命令的用户输入选择
【发布时间】:2012-10-22 16:45:00
【问题描述】:

我想通过命令行提示用户并询问需要使用头部或尾部从数据文件中剪切哪些特定行。我的脚本将使用 head 和 tail 使用输入作为 head 和 tail 命令的变量。到目前为止,这是我所拥有的错误消息:

echo -n "What rows need to be cut from your data file: "
read before
read after
head -n $before /home/rent_list
tail -n $after /home/rent_list 

错误信息:

-bash: ./rent_list: bin/bash: bad interpreter: No such file or directory

更新:这是我现在得到的:

 What rows need to be cut from your data file: 4

Mack Tools  Milwaukee Wisconsin mj414@yahoo.com 414 2248893
Terry Tools Orlando Florida 407@yahoo.com 407 2439812
Park Tools  Riviera Beach Florida tp123@hotmail.com 516 5370923
Bike Tools  Orlando Florida baptiste41@gmail.com 407 3420983
tail: /home/renter_list: invalid number of lines

【问题讨论】:

    标签: bash shell tail head


    【解决方案1】:

    错误消息似乎是说您的脚本以#!bin/bash 而不是#!/bin/bash 开头(也就是说,您在bin/bash 之前缺少/)。


    更新:您的新错误消息是因为您没有输入数字。你有一个echo,后面跟着两个reads。对于第一个read,您输入的是4,但对于第二个,您只需按Enter。所以tail 命令就是tail -n /home/rent_list

    如果你想对两个命令使用相同的数字,你可以这样写:

    echo -n "What rows need to be cut from your data file: "
    read num_rows
    head -n $num_rows /home/rent_list
    tail -n $num_rows /home/rent_list
    

    【讨论】:

    • 谢谢 ruakh,这就是我需要知道的。
    猜你喜欢
    • 1970-01-01
    • 2021-01-30
    • 1970-01-01
    • 2013-06-29
    • 2014-11-02
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 2020-12-07
    相关资源
    最近更新 更多