bash - Make perl exit with 1 if a string is found -


i want bash command (perl?) output non-zero exit code if non-ascii character found in text file.

here's have far:

perl -nle 'print "$." if m/[\x80-\xff]/' file_that_has_non_ascii_characters.txt 

this prints out each line non-ascii character found on. tried variant exit 1 in it, doesn't seem work:

➜ perl -nle 'exit 1 if m/[\x80-\xff]/' file_that_has_non_ascii_characters.txt ➜ echo $! 0 

how do this?

you should using $? instead of $!.

!: expands process id of executed background (asynchronous) command.

?: expands exit status of executed foreground pipeline.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -