There are times that we struggle with basic stuff and forum links are either expired or circular. One such stuff is calculate the average coverage for any given region in a bam file. Since bam format is ubiquitous in alignment, we assume that there are several tools can do this. Many tools exist to manipulate bam files, but none of them do little beyond basic stuff. But most of the commands are convoluted or require more than bam files (.bed, .fa and so on so forth). In addition, different tools use different cut-offs (as default) in producing read depth. They are not documented and even if they are, they will be some where tucked in the corner either in source code or  serpentine manuals. In general, manuals are like tax laws. You need an expert to get full advantage of the system. Okay, let us move on to topic. Let us say you want coverage for a region and you are given a bam file without reference sequence file or a bed file. Samtools and IGVtools can help you out. But if you use default arguments, you end up vastly different values. Below are the three commands which give you comparable coverage for any given region:

$ samtools depth -a -d 100000  -r  chr17:41243668-41246110 test.bam | datamash mean 3

output: 27012.516987311.

-a = for all sites
-d = maximum depth cutoff
-r = region

27012.516987311

$ samtools mpileup -ABQ0 -d 100000  -r  chr17:41243668-41246110 test.bam | datamash mean 4

output:  27016.835448219

-A = do not skip any anomalous reads
-BQ0= cut off BQ value is 0
-d = maximum depth cutoff

$ igvtools count  -w 1 --query  chr17:41243668-41246110 test.bam test.wig hg19
$ sed '1,2d' test3.wig | datamash mean 2

output:
27013.084731887

-w = width of the window
hg19= build name. IGV stores the genome information igv/genomes folder in your home folder if you are on linux. Or you can use chrom.sizes (https://github.com/igvteam/igv/tree/master/resources/chromSizes) instead of genome (hg19 here)
test.wig = output file in wig format. Wig format tab separated format.
'1,2'd = delete first two lines

Link to download IGV tools is available under "Install igvtools" section in page: https://software.broadinstitute.org/software/igv/download.