2012-10-22 23 views
1

我想通过命令行&提示用户使用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 [email protected] 414 2248893 
Terry Tools Orlando Florida [email protected] 407 2439812 
Park Tools Riviera Beach Florida [email protected] 516 5370923 
Bike Tools Orlando Florida [email protected] 407 3420983 
tail: /home/renter_list: invalid number of lines 

回答

4

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


更新:你的新的错误消息,是因为你没有输入号码。你有一个echo,其次是两个read s。对于第一个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 
+0

感谢ruakh,我固定环境变量.. – demet8

+0

感谢ruakh,这就是我需要知道。 – demet8

+0

@ demet8:不客气! – ruakh