diff --git a/samtools.wdl b/samtools.wdl
index b9e7d912b5ae31de893aeba9ed32bbf35bacfb30..395c9acdc8a83efa426aeabf0ff67bb9b59119d1 100644
--- a/samtools.wdl
+++ b/samtools.wdl
@@ -34,15 +34,16 @@ task Index {
         String dockerImage = "quay.io/biocontainers/samtools:1.8--h46bd0b3_5"
     }
     String bamPath = basename(bamFile)
+    String bamIndexPath = sub(bamPath, "\.bam$", ".bai")
 
     command {
         ln ~{bamFile} ~{bamPath}
-        samtools index ~{bamPath}
+        samtools index ~{bamPath} ~{bamIndexPath}
     }
 
     output {
         File indexedBam = bamPath
-        File index =  sub(bamPath, "\.bam$", ".bai")
+        File index =  bamIndexPath
     }
 
     runtime {