OK, the main issue here is that there is no such thing as line 0. sed
starts counting lines from 1. Presumably, assuming the rest of your script is OK, this should work:
#!/usr/bin/env bash
sed -n "$2,$3p" "$1"
I tried the script above on this file:
$ cat file
line 1
line 2
line 3
line 4
line 5
line 6
$ ./foo.sh file 3 5
line 3
line 4
line 5
$ ./foo.sh file 0 5
sed: -e expression #1, char 4: invalid usage of line address 0
$ ./foo.sh file 1 3
line 1
line 2
line 3
From man sed
(thanks @manatwork):
0,addr2
Start out in "matched first address" state, until addr2 is
found. This is similar to 1,addr2, except that if addr2 matches
the very first line of input the 0,addr2 form will be at the end
of its range, whereas the 1,addr2 form will still be at the
beginning of its range. This works only when addr2 is a regular
expression.
So, this should work as well:
$ a.sh file 0 "/line 3/"
line 1
line 2
line 3
If you are using normal named variables, it will fail because your shell has no way of knowing where the variable's name ends and the sed
commands begin. For example:
foo=1; sed -n "$foop"
will print nothing since the shell will treat $foop
as the variable name. To get around that, use curly braces:
$ foo=1; sed -n "${foo}p" file
line 1