I want to find all my bash scripts (I have accumulated a lot of them now) and automatically run them through bash -n .
What is a quick way to do this? I would like grep match only files whose first non-empty lines start with #!/bin/sh or #!/usr/bin/env sh or #!/usr/bin/env bash or #!/bin/bash . ..
The correct answer is, of course, something like
for file in *; do if head -n 5 $file | grep "#!.*sh$" > /dev/null; then bash -n $file fi done
But for the sake of "correctness", how can I reasonably make my grep on only the first line without spaces (or, alternatively, not empty) ?
source share