Sample Header Ad - 728x90

grep behaviour is different when run using bash -c '...'

0 votes
1 answer
723 views
I met an interesting issue while working with this code from Stack Overflow: tripleee's answer on "How to check if a file contains only zeros in a Linux shell?" Why does the same bash code produce different result depending on interactive shell or subshell? Make all-zeros file with name your_file.
$ truncate -s 1K your_file
Interactive shell example
$ tr -d '\0' 
The same code but using subshell
$ bash -c 'tr -d '\0' 
And also interesting fact. I changed original example by adding -a option ("equivalent to --binary-files=text") because without this option interactive shell works but subshell:
$ bash -c 'tr -d '\0' 
P.S. I use bash 5.2.37(1)-release from Ubuntu 25.04
Asked by Андрей Тернити (303 rep)
Jul 21, 2025, 01:34 PM
Last activity: Jul 24, 2025, 04:33 AM