diff --git a/.travis.yml b/.travis.yml
index 825ac43480b598f42ff0ac7bc52801dadabb9c65..2e7f548a03ba4c28e29bd565e80aca2492e18add 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,43 +2,30 @@ language: rust
 rust: stable
 sudo: required
 dist: trusty
-services:
-  - docker
-install:
-  - if [ -z "$NO_ADD" ]; then rustup target add $TARGET; fi
-script:
-  - cargo build $OPT
-  - cargo build $OPT --no-default-features
-  - cargo generate-lockfile --manifest-path libc-test/Cargo.toml
-  - if [[ $TRAVIS_OS_NAME = "linux" ]]; then
-      sh ci/run-docker.sh $TARGET;
-    else
-      export CARGO_TARGET_DIR=`pwd`/target;
-      sh ci/run.sh $TARGET;
-    fi
-  - rustc ci/style.rs && ./style src
-env:
-  global:
-    secure: "e2/3QjgRN9atOuSHp22TrYG7QVKcYUWY48Hi9b60w+r1+BhPkTseIJLte7WefRhdXtqpjjUJTooKDhnurFOeHaCT+nmBgiv+FPU893sBl4bhesY4m0vgUJVbNZcs6lTImYekWVb+aqjGdgV/XAgCw7c3kPmrZV0MzGDWL64Xaps="
+services: docker
+
 matrix:
   include:
     # 1.13.0 compat
-    - env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1
+    - env: TARGET=x86_64-unknown-linux-gnu
       rust: 1.13.0
       script: rm -f Cargo.lock && cargo build
-      install:
+      install: true
 
     # build documentation
-    - env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1
+    - env: TARGET=x86_64-unknown-linux-gnu
       rust: nightly
       script: sh ci/dox.sh
+      install: true
 
     # stable compat
-    - env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1
+    - env: TARGET=x86_64-unknown-linux-gnu
+      install: true
     - env: TARGET=i686-unknown-linux-gnu
     - os: osx
-      env: TARGET=x86_64-apple-darwin NO_ADD=1
+      env: TARGET=x86_64-apple-darwin
       osx_image: xcode10
+      install: true
     - os: osx
       env: TARGET=i686-apple-darwin
       osx_image: xcode10
@@ -67,20 +54,24 @@ matrix:
     - env: TARGET=wasm32-unknown-emscripten
 
     # beta
-    - env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1
+    - env: TARGET=x86_64-unknown-linux-gnu
       rust: beta
+      install: true
     - os: osx
-      env: TARGET=x86_64-apple-darwin NO_ADD=1
+      env: TARGET=x86_64-apple-darwin
       osx_image: xcode10
       rust: beta
+      install: true
 
     # nightly
-    - env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1
+    - env: TARGET=x86_64-unknown-linux-gnu
       rust: nightly
+      install: true
     - os: osx
-      env: TARGET=x86_64-apple-darwin NO_ADD=1
+      env: TARGET=x86_64-apple-darwin
       osx_image: xcode10
       rust: nightly
+      install: true
     # not available on stable
     # without --release the build fails
     # see https://github.com/rust-lang/rust/issues/45417
@@ -90,15 +81,26 @@ matrix:
     # QEMU based targets that compile in an emulator
     - env: TARGET=x86_64-unknown-freebsd
 
-    - name: "rustfmt"
-      install: rustup component add rustfmt-preview
-      script: cargo fmt --all -- --check
     - name: "Shellcheck"
       install: true
       script:
         - shellcheck --version
         - shellcheck ci/*.sh
 
+install: rustup target add $TARGET
+script:
+  - cargo generate-lockfile --manifest-path libc-test/Cargo.toml
+  - if [[ $TRAVIS_OS_NAME = "linux" ]]; then
+      sh ci/run-docker.sh $TARGET;
+    else
+      export CARGO_TARGET_DIR=`pwd`/target;
+      sh ci/run.sh $TARGET;
+    fi
+  - rustc ci/style.rs && ./style src
+env:
+  global:
+    secure: "e2/3QjgRN9atOuSHp22TrYG7QVKcYUWY48Hi9b60w+r1+BhPkTseIJLte7WefRhdXtqpjjUJTooKDhnurFOeHaCT+nmBgiv+FPU893sBl4bhesY4m0vgUJVbNZcs6lTImYekWVb+aqjGdgV/XAgCw7c3kPmrZV0MzGDWL64Xaps="
+
 notifications:
   email:
     on_success: never
diff --git a/ci/android-install-ndk.sh b/ci/android-install-ndk.sh
index 873f6c52c8f189c8de42edf4c0c3c3f406a7e394..4a5fbc0ba16ca99a9297fc4f940485e0454c5784 100644
--- a/ci/android-install-ndk.sh
+++ b/ci/android-install-ndk.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env sh
 # Copyright 2016 The Rust Project Developers. See the COPYRIGHT
 # file at the top-level directory of this distribution and at
 # http://rust-lang.org/COPYRIGHT.
@@ -30,8 +30,8 @@ esac;
 
 android-ndk-r15b/build/tools/make_standalone_toolchain.py \
         --unified-headers \
-        --install-dir /android/ndk-$1 \
-        --arch $arch \
+        --install-dir "/android/ndk-${1}" \
+        --arch "${arch}" \
         --api 24
 
 rm -rf ./android-ndk-r15b-linux-x86_64.zip ./android-ndk-r15b
diff --git a/ci/android-install-sdk.sh b/ci/android-install-sdk.sh
index ab7e14d95be2541de76612fcc42fd8488b02b5e8..e43cbc3a6becd91a1143fa073b1d37bb7fdf0cf7 100644
--- a/ci/android-install-sdk.sh
+++ b/ci/android-install-sdk.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env sh
 # Copyright 2016 The Rust Project Developers. See the COPYRIGHT
 # file at the top-level directory of this distribution and at
 # http://rust-lang.org/COPYRIGHT.
@@ -56,5 +56,5 @@ echo "yes" | \
 
 echo "no" |
     ./sdk/tools/bin/avdmanager create avd \
-        --name $1 \
+        --name "${1}" \
         --package "system-images;android-24;default;$abi"
diff --git a/ci/android-sysimage.sh b/ci/android-sysimage.sh
index 9611dfeb0d529ee7c19ac7e8316f5b8c5ba8a373..1a6c49d2d433f96cb369ebe22338ad4545437bc0 100644
--- a/ci/android-sysimage.sh
+++ b/ci/android-sysimage.sh
@@ -1,3 +1,5 @@
+#!/usr/bin/env bash
+
 # Copyright 2017 The Rust Project Developers. See the COPYRIGHT
 # file at the top-level directory of this distribution and at
 # http://rust-lang.org/COPYRIGHT.
@@ -13,32 +15,34 @@ set -ex
 URL=https://dl.google.com/android/repository/sys-img/android
 
 main() {
-    local arch=$1
-    local name=$2
+    local arch="${1}"
+    local name="${2}"
     local dest=/system
-    local td=$(mktemp -d)
+    local td
+    td="$(mktemp -d)"
 
     apt-get install --no-install-recommends e2tools
 
-    pushd $td
-    curl -O $URL/$name
-    unzip -q $name
+    pushd "${td}"
+    curl -O "${URL}/${name}"
+    unzip -q "${name}"
 
-    local system=$(find . -name system.img)
-    mkdir -p $dest/{bin,lib,lib64}
+    local system
+    system="$(find . -name system.img)"
+    mkdir -p ${dest}/{bin,lib,lib64}
 
     # Extract android linker and libraries to /system
     # This allows android executables to be run directly (or with qemu)
-    if [ $arch = "x86_64" -o $arch = "arm64" ]; then
-        e2cp -p $system:/bin/linker64 $dest/bin/
-        e2cp -p $system:/lib64/libdl.so $dest/lib64/
-        e2cp -p $system:/lib64/libc.so $dest/lib64/
-        e2cp -p $system:/lib64/libm.so $dest/lib64/
+    if [ "${arch}" = "x86_64" ] || [ "${arch}" = "arm64" ]; then
+        e2cp -p "${system}:/bin/linker64" "${dest}/bin/"
+        e2cp -p "${system}:/lib64/libdl.so" "${dest}/lib64/"
+        e2cp -p "${system}:/lib64/libc.so" "${dest}/lib64/"
+        e2cp -p "${system}:/lib64/libm.so" "${dest}/lib64/"
     else
-        e2cp -p $system:/bin/linker $dest/bin/
-        e2cp -p $system:/lib/libdl.so $dest/lib/
-        e2cp -p $system:/lib/libc.so $dest/lib/
-        e2cp -p $system:/lib/libm.so $dest/lib/
+        e2cp -p "${system}:/bin/linker" "${dest}/bin/"
+        e2cp -p "${system}:/lib/libdl.so" "${dest}/lib/"
+        e2cp -p "${system}:/lib/libc.so" "${dest}/lib/"
+        e2cp -p "${system}:/lib/libm.so" "${dest}/lib/"
     fi
 
     # clean up
@@ -46,7 +50,7 @@ main() {
 
     popd
 
-    rm -rf $td
+    rm -rf "${td}"
 }
 
 main "${@}"
diff --git a/ci/dox.sh b/ci/dox.sh
index b8ffa7dd0d0741a237e07c8ededf4167192ba60a..521743e39946bca5a4a18b3eee1c3be043c5b91f 100644
--- a/ci/dox.sh
+++ b/ci/dox.sh
@@ -1,12 +1,12 @@
-#!/bin/sh
+#!/usr/bin/env sh
 
 # Builds documentation for all target triples that we have a registered URL for
 # in liblibc. This scrapes the list of triples to document from `src/lib.rs`
 # which has a bunch of `html_root_url` directives we pick up.
 
-set -e
+set -ex
 
-TARGETS=`grep html_root_url src/lib.rs | sed 's/.*".*\/\(.*\)"/\1/'`
+TARGETS=$(grep html_root_url src/lib.rs | sed 's/.*".*\/\(.*\)"/\1/'| sed 's/)//')
 
 rm -rf target/doc
 mkdir -p target/doc
@@ -14,12 +14,12 @@ mkdir -p target/doc
 cp ci/landing-page-head.html target/doc/index.html
 
 for target in $TARGETS; do
-  echo documenting $target
+  echo "documenting ${target}"
 
-  rustdoc -o target/doc/$target --target $target src/lib.rs --cfg cross_platform_docs \
+  rustdoc -o "target/doc/${target}" --target "${target}" src/lib.rs --cfg cross_platform_docs \
     --crate-name libc
 
-  echo "<li><a href="/libc/$target/libc/index.html">$target</a></li>" \
+  echo "<li><a href=\"/libc/${target}/libc/index.html\">${target}</a></li>" \
     >> target/doc/index.html
 done
 
@@ -28,6 +28,6 @@ cat ci/landing-page-footer.html >> target/doc/index.html
 # If we're on travis, not a PR, and on the right branch, publish!
 if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_BRANCH" = "master" ]; then
   pip install ghp_import --install-option="--prefix=$HOME/.local"
-  $HOME/.local/bin/ghp-import -n target/doc
-  git push -qf https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
+  "${HOME}/.local/bin/ghp-import" -n target/doc
+  git push -qf "https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git" gh-pages
 fi
diff --git a/ci/emscripten-entry.sh b/ci/emscripten-entry.sh
index 22ae8b08a3ae5b0e44fee2c7e51412a32769c48f..e92c1cb1bf60575cfa32bcb464a36e475f314a93 100755
--- a/ci/emscripten-entry.sh
+++ b/ci/emscripten-entry.sh
@@ -11,6 +11,7 @@
 
 set -ex
 
+# shellcheck disable=SC1091
 source /emsdk-portable/emsdk_env.sh &> /dev/null
 
 # emsdk-portable provides a node binary, but we need version 8 to run wasm
diff --git a/ci/emscripten.sh b/ci/emscripten.sh
index d80258584d21afa398520bd0b4543505122a8dc6..ab69aa7514357c006da30dda64024b5f36fdcd6e 100644
--- a/ci/emscripten.sh
+++ b/ci/emscripten.sh
@@ -1,3 +1,4 @@
+#!/usr/bin/env bash
 # Copyright 2017 The Rust Project Developers. See the COPYRIGHT
 # file at the top-level directory of this distribution and at
 # http://rust-lang.org/COPYRIGHT.
@@ -17,10 +18,10 @@ echo ERROR: An error was encountered with the build.
 cat /tmp/build.log
 exit 1
 "
-  trap "$on_err" ERR
+  trap '$on_err' ERR
   bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
   PING_LOOP_PID=$!
-  $@ &> /tmp/build.log
+  "${@}" &> /tmp/build.log
   trap - ERR
   kill $PING_LOOP_PID
   rm -f /tmp/build.log
@@ -37,6 +38,7 @@ hide_output ./emsdk install sdk-1.37.20-64bit
 ./emsdk activate sdk-1.37.20-64bit
 
 # Compile and cache libc
+# shellcheck disable=SC1091
 source ./emsdk_env.sh
 echo "main(){}" > a.c
 HOME=/emsdk-portable/ emcc a.c
diff --git a/ci/linux-s390x.sh b/ci/linux-s390x.sh
index 972abeec569ece97403449f0abd2a424c14f0805..95cb798ac47eb01efbfd68984628e73dfdf4d246 100644
--- a/ci/linux-s390x.sh
+++ b/ci/linux-s390x.sh
@@ -1,3 +1,5 @@
+#!/usr/bin/env sh
+
 set -ex
 
 mkdir -m 777 /qemu
diff --git a/ci/linux-sparc64.sh b/ci/linux-sparc64.sh
index 4452b120e1b6c53450b80ec9b95da9a8e7a2f99f..69c405b8792fb941b45cf964235fcb8479df0585 100644
--- a/ci/linux-sparc64.sh
+++ b/ci/linux-sparc64.sh
@@ -1,3 +1,5 @@
+#!/usr/bin/env sh
+
 set -ex
 
 mkdir -m 777 /qemu
diff --git a/ci/run-docker.sh b/ci/run-docker.sh
index 662a1d491ad701c06d91ad2a8fd5d9341cc372b6..4247827f67ffcf7d216afcf746842d15b8e64942 100755
--- a/ci/run-docker.sh
+++ b/ci/run-docker.sh
@@ -1,36 +1,41 @@
+#!/usr/bin/env sh
+
 # Small script to run tests for a target (or all targets) inside all the
 # respective docker images.
 
 set -ex
 
 run() {
-    echo $1
+    echo "Building docker container for target ${1}"
     # use -f so we can use ci/ as build context
-    docker build -t libc -f ci/docker/$1/Dockerfile ci/
+    docker build -t libc -f "ci/docker/${1}/Dockerfile" ci/
     mkdir -p target
     if [ -w /dev/kvm ]; then
-      kvm="--volume /dev/kvm:/dev/kvm"
+        kvm="--volume /dev/kvm:/dev/kvm"
+    else
+        kvm=""
     fi
+
     docker run \
-      --user `id -u`:`id -g` \
+      --user "$(id -u)":"$(id -g)" \
       --rm \
       --init \
-      --volume $HOME/.cargo:/cargo \
+      --volume "${HOME}/.cargo":/cargo \
       $kvm \
       --env CARGO_HOME=/cargo \
-      --volume `rustc --print sysroot`:/rust:ro \
-      --volume `pwd`:/checkout:ro \
-      --volume `pwd`/target:/checkout/target \
+      --volume "$(rustc --print sysroot)":/rust:ro \
+      --volume "$(pwd)":/checkout:ro \
+      --volume "$(pwd)"/target:/checkout/target \
       --env CARGO_TARGET_DIR=/checkout/target \
       --workdir /checkout \
       libc \
-      ci/run.sh $1
+      ci/run.sh "${1}"
 }
 
-if [ -z "$1" ]; then
-  for d in `ls ci/docker/`; do
-    run $d
+if [ -z "${1}" ]; then
+  for d in ci/docker/*; do
+    run "${d}"
   done
 else
-  run $1
+  run "${1}"
 fi
diff --git a/ci/run-qemu.sh b/ci/run-qemu.sh
index b2f457df916f85688dce328af91b06543fad6ff6..6fba6298768f4b06606d62e602a137e095166c03 100644
--- a/ci/run-qemu.sh
+++ b/ci/run-qemu.sh
@@ -1,3 +1,5 @@
+#!/usr/bin/env sh
+
 # Initial script which is run inside of all qemu images. The first argument to
 # this script (as arranged by the qemu image itself) is the path to where the
 # libc crate is mounted.
@@ -10,11 +12,11 @@
 
 set -ex
 
-ROOT=$1
-cp -r $ROOT/libc /tmp/libc
+ROOT="${1}"
+cp -r "${ROOT}/libc" /tmp/libc
 cd /tmp/libc
 
-TARGET=$(cat $ROOT/TARGET)
+TARGET="$(cat "${ROOT}/TARGET")"
 export CARGO_TARGET_DIR=/tmp
 
 case $TARGET in
@@ -24,9 +26,9 @@ case $TARGET in
     ;;
 
   *)
-    echo "Unknown target: $TARGET"
+    echo "Unknown target: ${TARGET}"
     exit 1
     ;;
 esac
 
-exec sh ci/run.sh $TARGET
+exec sh ci/run.sh "${TARGET}"
diff --git a/ci/run.sh b/ci/run.sh
index 27ffc054a0814e82f9b780d34780ae7406a33287..2140da68e2fb719af2223ab211be40733517c3f7 100755
--- a/ci/run.sh
+++ b/ci/run.sh
@@ -1,11 +1,11 @@
-#!/bin/sh
+#!/usr/bin/env sh
 
 # Builds and runs tests for a particular target passed as an argument to this
 # script.
 
 set -ex
 
-TARGET=$1
+TARGET="${1}"
 
 # If we're going to run tests inside of a qemu image, then we don't need any of
 # the scripts below. Instead, download the image, prepare a filesystem which has
@@ -15,52 +15,53 @@ TARGET=$1
 # script from the second which we place inside.
 if [ "$QEMU" != "" ]; then
   tmpdir=/tmp/qemu-img-creation
-  mkdir -p $tmpdir
+  mkdir -p "${tmpdir}"
 
   if [ -z "${QEMU#*.gz}" ]; then
     # image is .gz : download and uncompress it
-    qemufile=$(echo ${QEMU%.gz} | sed 's/\//__/g')
-    if [ ! -f $tmpdir/$qemufile ]; then
-      curl https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/$QEMU | \
-        gunzip -d > $tmpdir/$qemufile
+    qemufile="$(echo "${QEMU%.gz}" | sed 's/\//__/g')"
+    if [ ! -f "${tmpdir}/${qemufile}" ]; then
+      curl "https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/${QEMU}" | \
+          gunzip -d > "${tmpdir}/${qemufile}"
     fi
   elif [ -z "${QEMU#*.xz}" ]; then
     # image is .xz : download and uncompress it
-    qemufile=$(echo ${QEMU%.xz} | sed 's/\//__/g')
-    if [ ! -f $tmpdir/$qemufile ]; then
-      curl https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/$QEMU | \
-        unxz > $tmpdir/$qemufile
+    qemufile="$(echo "${QEMU%.xz}" | sed 's/\//__/g')"
+    if [ ! -f "${tmpdir}/${qemufile}" ]; then
+      curl "https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/${QEMU}" | \
+          unxz > "${tmpdir}/${qemufile}"
     fi
   else
     # plain qcow2 image: just download it
-    qemufile=$(echo ${QEMU} | sed 's/\//__/g')
-    if [ ! -f $tmpdir/$qemufile ]; then
-      curl https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/$QEMU \
-        > $tmpdir/$qemufile
+    qemufile="$(echo "${QEMU}" | sed 's/\//__/g')"
+    if [ ! -f "${tmpdir}/${qemufile}" ]; then
+      curl "https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/${QEMU}" \
+        > "${tmpdir}/${qemufile}"
     fi
   fi
 
   # Create a mount a fresh new filesystem image that we'll later pass to QEMU.
   # This will have a `run.sh` script will which use the artifacts inside to run
   # on the host.
-  rm -f $tmpdir/libc-test.img
-  mkdir $tmpdir/mount
+  rm -f "${tmpdir}/libc-test.img"
+  mkdir "${tmpdir}/mount"
 
   # Do the standard rigamarole of cross-compiling an executable and then the
   # script to run just executes the binary.
   cargo build \
     --manifest-path libc-test/Cargo.toml \
-    --target $TARGET \
+    --target "${TARGET}" \
     --test main
-  rm $CARGO_TARGET_DIR/$TARGET/debug/main-*.d
-  cp $CARGO_TARGET_DIR/$TARGET/debug/main-* $tmpdir/mount/libc-test
-  echo 'exec $1/libc-test' > $tmpdir/mount/run.sh
+  rm "${CARGO_TARGET_DIR}/${TARGET}"/debug/main-*.d
+  cp "${CARGO_TARGET_DIR}/${TARGET}"/debug/main-* "${tmpdir}"/mount/libc-test
+  # shellcheck disable=SC2016
+  echo 'exec $1/libc-test' > "${tmpdir}/mount/run.sh"
 
-  du -sh $tmpdir/mount
+  du -sh "${tmpdir}/mount"
   genext2fs \
-      --root $tmpdir/mount \
+      --root "${tmpdir}/mount" \
       --size-in-blocks 100000 \
-      $tmpdir/libc-test.img
+      "${tmpdir}/libc-test.img"
 
   # Pass -snapshot to prevent tampering with the disk images, this helps when
   # running this script in development. The two drives are then passed next,
@@ -70,13 +71,13 @@ if [ "$QEMU" != "" ]; then
   qemu-system-x86_64 \
     -m 1024 \
     -snapshot \
-    -drive if=virtio,file=$tmpdir/$qemufile \
-    -drive if=virtio,file=$tmpdir/libc-test.img \
+    -drive if=virtio,file="${tmpdir}/${qemufile}" \
+    -drive if=virtio,file="${tmpdir}/libc-test.img" \
     -net nic,model=virtio \
     -net user \
     -nographic \
-    -vga none 2>&1 | tee $CARGO_TARGET_DIR/out.log
-  exec grep "^PASSED .* tests" $CARGO_TARGET_DIR/out.log
+    -vga none 2>&1 | tee "${CARGO_TARGET_DIR}/out.log"
+  exec grep "^PASSED .* tests" "${CARGO_TARGET_DIR}/out.log"
 fi
 
 # FIXME: x86_64-unknown-linux-gnux32 fail to compile without --release
@@ -89,10 +90,10 @@ fi
 # Building with --no-default-features is currently broken on rumprun because we
 # need cfg(target_vendor), which is currently unstable.
 if [ "$TARGET" != "x86_64-rumprun-netbsd" ]; then
-  cargo test $opt --no-default-features --manifest-path libc-test/Cargo.toml --target $TARGET
+  cargo test $opt --no-default-features --manifest-path libc-test/Cargo.toml --target "${TARGET}"
 fi
 # Test the #[repr(align(x))] feature if this is building on Rust >= 1.25
-if [ $(rustc --version | sed -E 's/^rustc 1\.([0-9]*)\..*/\1/') -ge 25 ]; then
-  cargo test $opt --features align --manifest-path libc-test/Cargo.toml --target $TARGET
+if [ "$(rustc --version | sed -E 's/^rustc 1\.([0-9]*)\..*/\1/')" -ge 25 ]; then
+  cargo test $opt --features align --manifest-path libc-test/Cargo.toml --target "${TARGET}"
 fi
-exec cargo test $opt --manifest-path libc-test/Cargo.toml --target $TARGET
+exec cargo test $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}"