I want to print out the lines of a file between two indices in a Bash script. I have the file name and indices as variablesI tried doing this sed -n $2,$3p $1sed: -e expression #1, char 4: invalid usage of line address 0but I got an error. How do I do this? 
How to use variables in sed
bash;sed;bash script
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 bashsed -n $2,$3p $1I tried the script above on this file:$ cat fileline 1line 2line 3line 4line 5line 6$ ./foo.sh file 3 5line 3line 4line 5$ ./foo.sh file 0 5sed: -e expression #1, char 4: invalid usage of line address 0$ ./foo.sh file 1 3line 1line 2line 3From man sed (thanks @manatwork):0,addr2Start  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 1line 2line 3If 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 $foopwill 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 fileline 1