Make integration tests more portable

By avoiding paths that are too specific for a given system, and bringing
option arguments before non-option arguments.

Change-Id: I82acae94e2d9808c9e81a85018c6a0578da8bd42
PiperOrigin-RevId: 160957203
diff --git a/src/test/shell/integration/java_integration_test.sh b/src/test/shell/integration/java_integration_test.sh
index 7c4f5d2..82e0bb3 100755
--- a/src/test/shell/integration/java_integration_test.sh
+++ b/src/test/shell/integration/java_integration_test.sh
@@ -373,7 +373,7 @@
   write_hello_library_files "$pkg"
 
   bazel build //$pkg/java/main:main_deploy.jar || fail "build failed"
-  touch old -r ${PRODUCT_NAME}-bin/$pkg/java/main/main_deploy.jar
+  touch -r ${PRODUCT_NAME}-bin/$pkg/java/main/main_deploy.jar old
   bazel build //$pkg/java/main:main_deploy.jar || fail "build failed"
   find ${PRODUCT_NAME}-bin/$pkg/java/main/main_deploy.jar -newer old \
     | grep -q . && fail "file was rebuilt"
diff --git a/src/test/shell/integration/output_filter_test.sh b/src/test/shell/integration/output_filter_test.sh
index 7b82ec7..3d15b7f 100755
--- a/src/test/shell/integration/output_filter_test.sh
+++ b/src/test/shell/integration/output_filter_test.sh
@@ -127,7 +127,7 @@
 EOF
 
   cat >foo/bar/test.sh <<EOF
-#!/bin/bash
+#!/bin/sh
 exit 0
 EOF
 
@@ -226,13 +226,13 @@
 EOF
 
   cat >geflugel/mockingbird.sh <<EOF
-#!/bin/bash
+#!/bin/sh
 echo "To kill -9 a mockingbird"
 exit 1
 EOF
 
   cat >geflugel/hummingbird.sh <<EOF
-#!/bin/bash
+#!/bin/sh
 echo "To kill -9 a hummingbird"
 exit 1
 EOF
diff --git a/src/test/shell/integration/progress_reporting_test.sh b/src/test/shell/integration/progress_reporting_test.sh
index ab98672..b42e28e 100755
--- a/src/test/shell/integration/progress_reporting_test.sh
+++ b/src/test/shell/integration/progress_reporting_test.sh
@@ -150,7 +150,7 @@
   # implementation to have a progress message, because it breaks all kinds of
   # things.
   cat >"${pkg}/workspace_status.sh" <<EOF
-#!/bin/bash
+#!/bin/sh
 sleep 5
 EOF
 
diff --git a/src/test/shell/integration/run_test.sh b/src/test/shell/integration/run_test.sh
index b322c85..664198c 100755
--- a/src/test/shell/integration/run_test.sh
+++ b/src/test/shell/integration/run_test.sh
@@ -177,7 +177,7 @@
   rm -f "$pipe_file"
   mkfifo "$pipe_file" || fail "make pipe failed"
   echo 'sh_binary(name = "sleep-minute", srcs = ["sleep-minute.sh"])' > foo/BUILD
-  echo -e "#!/bin/bash\n"'echo $$ >'"${pipe_file}\n"'sleep 60' > foo/sleep-minute.sh
+  echo -e "#!/bin/sh\n"'echo $$ >'"${pipe_file}\n"'sleep 60' > foo/sleep-minute.sh
   chmod +x foo/sleep-minute.sh
   # Note that if bazel info is not executed before the actual bazel run, this script would have to
   # be run in "monitor mode" (with the command set -m) for bazel or the server to receive SIGINT.
@@ -293,7 +293,7 @@
 EOF
 
   cat > some/testing/test.sh <<'EOF'
-#!/bin/bash
+#!/usr/bin/env bash
 set -ex
 echo "Got $@"
 i=1
@@ -319,7 +319,7 @@
 EOF
 
   cat > a/a.sh <<EOF
-#!/bin/bash
+#!/bin/sh
 echo "Dancing with wolves"
 exit 0
 EOF
diff --git a/src/test/shell/integration/stub_finds_runfiles_test.sh b/src/test/shell/integration/stub_finds_runfiles_test.sh
index a608625..fe366bd 100755
--- a/src/test/shell/integration/stub_finds_runfiles_test.sh
+++ b/src/test/shell/integration/stub_finds_runfiles_test.sh
@@ -76,19 +76,19 @@
 touch pkg/pybin.py
 touch pkg/pytest.py
 cat > pkg/sh_runs_javabin.sh << 'EOF'
-#!/bin/bash
+#!/bin/sh
 exec $0.runfiles/*/pkg/javabin
 EOF
 cat > pkg/sh_runs_javatest.sh << 'EOF'
-#!/bin/bash
+#!/bin/sh
 exec $TEST_SRCDIR/*/pkg/javatest
 EOF
 cat > pkg/sh_runs_pybin.sh << 'EOF'
-#!/bin/bash
+#!/bin/sh
 exec $0.runfiles/*/pkg/pybin
 EOF
 cat > pkg/sh_runs_pytest.sh << 'EOF'
-#!/bin/bash
+#!/bin/sh
 exec $TEST_SRCDIR/*/pkg/pytest
 EOF
 chmod +x pkg/*.sh
diff --git a/src/test/shell/integration/test_test.sh b/src/test/shell/integration/test_test.sh
index f41a36b..7483ca0 100755
--- a/src/test/shell/integration/test_test.sh
+++ b/src/test/shell/integration/test_test.sh
@@ -32,7 +32,7 @@
 )
 EOF
   cat >tests/success.sh <<'EOF'
-#!/bin/bash
+#!/bin/sh
 
 echo "success.sh is successful"
 exit 0
@@ -55,7 +55,7 @@
 )
 EOF
   cat >tests/fail.sh <<'EOF'
-#!/bin/bash
+#!/bin/sh
 
 echo "fail.sh is failing"
 exit 42