diff mbox series

[PATCHv2,3/4] scripts/clean-package.sh: remove useless cat

Message ID 20200711184528.47605-3-rosenp@gmail.com
State New
Headers show
Series [PATCHv2,1/4] scripts/clean-package.sh: exit in case cd fails | expand

Commit Message

Rosen Penev July 11, 2020, 6:45 p.m. UTC
Found with shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 v2: rebased
 scripts/clean-package.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Paul Spooren July 11, 2020, 11:38 p.m. UTC | #1
Hi,

On 11.07.20 08:45, Rosen Penev wrote:
> Found with shellcheck.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>   v2: rebased
>   scripts/clean-package.sh | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/clean-package.sh b/scripts/clean-package.sh
> index 4b536c8a48..03e49df3e7 100755
> --- a/scripts/clean-package.sh
> +++ b/scripts/clean-package.sh
> @@ -8,13 +8,13 @@ IFS=$'\n'
>   	echo "File/directory not found"
>   	exit 1
>   }
> -cat "$1" | (
> +(
>   	cd "$2" || exit 1
>   	while read -r entry; do
>   		[ -n "$entry" ] || break
>   		[ ! -d "$entry" ] || [ -L "$entry" ] && rm -f "$entry"
>   	done
> -)
> +) < "$1"
>   sort -r "$1" | (
>   	cd "$2" || exit 1
>   	while read -r entry; do
I'd be curious whats wrong here, do you mind adding the SC numbers to 
future improvements?
Alberto Bursi July 12, 2020, 12:12 a.m. UTC | #2
On 12/07/20 01:38, Paul Spooren wrote:
> Hi,
> 
> On 11.07.20 08:45, Rosen Penev wrote:
>> Found with shellcheck.
>>
>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>> ---
>>   v2: rebased
>>   scripts/clean-package.sh | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/scripts/clean-package.sh b/scripts/clean-package.sh
>> index 4b536c8a48..03e49df3e7 100755
>> --- a/scripts/clean-package.sh
>> +++ b/scripts/clean-package.sh
>> @@ -8,13 +8,13 @@ IFS=$'\n'
>>       echo "File/directory not found"
>>       exit 1
>>   }
>> -cat "$1" | (
>> +(
>>       cd "$2" || exit 1
>>       while read -r entry; do
>>           [ -n "$entry" ] || break
>>           [ ! -d "$entry" ] || [ -L "$entry" ] && rm -f "$entry"
>>       done
>> -)
>> +) < "$1"
>>   sort -r "$1" | (
>>       cd "$2" || exit 1
>>       while read -r entry; do
> I'd be curious whats wrong here, do you mind adding the SC numbers to 
> future improvements?
> 

It's said in the commit title, "remove useless cat"
which is a kind of well-known topic for shell experts.

"The purpose of cat is to concatenate (or "catenate") files. If it's 
only one file, concatenating it with nothing at all is a waste of time, 
and costs you a process."

 From "Useless Use of Cat Award"
http://porkmail.org/era/unix/award.html

-Alberto
diff mbox series

Patch

diff --git a/scripts/clean-package.sh b/scripts/clean-package.sh
index 4b536c8a48..03e49df3e7 100755
--- a/scripts/clean-package.sh
+++ b/scripts/clean-package.sh
@@ -8,13 +8,13 @@  IFS=$'\n'
 	echo "File/directory not found"
 	exit 1
 }
-cat "$1" | (
+(
 	cd "$2" || exit 1
 	while read -r entry; do
 		[ -n "$entry" ] || break
 		[ ! -d "$entry" ] || [ -L "$entry" ] && rm -f "$entry"
 	done
-)
+) < "$1"
 sort -r "$1" | (
 	cd "$2" || exit 1
 	while read -r entry; do