[PATCH] scripts/bash_aliases: srcfix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I clarified the code about two things:

- Checking how many arguments are being passed.
    Here, some functions didn't reject extra arguments when they
    weren't being used.  Fix that.
    I also changed the code to use $#, which is more explicit.
    And use arithmetic expressions, which better indicate that
    we're dealing with numbers.

- Remove unneeded options from sort.
    Reported-by: Stefan Puiu <stefan.puiu@xxxxxxxxx>
    After Stefan asked about why am I using 'sort -V',
    I noticed that I really don't need '-V', and it may confuse
    people trying to understand the script, so even though I
    slightly prefer the output of 'sort -V', in this case, it's
    better to use the simpler 'sort' (yet I need 'sort', to
    maintain consistency in the results (find is quite random)).

Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx>
---
 scripts/bash_aliases | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/scripts/bash_aliases b/scripts/bash_aliases
index a14026bda..358e2f37a 100644
--- a/scripts/bash_aliases
+++ b/scripts/bash_aliases
@@ -45,20 +45,20 @@ function sed_rm_ccomments()
 
 function grep_syscall()
 {
-	if ! [ -v 1 ]; then
+	if (($# != 1)); then
 		>&2 echo "Usage: ${FUNCNAME[0]} <syscall>";
 		return ${EX_USAGE};
 	fi
 
 	find * -type f \
 	|grep '\.c$' \
-	|sort -V \
+	|sort \
 	|xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\(${1},.*?\)" \
 	|sed -E 's/^[^:]+:[0-9]+:/&\n/';
 
 	find * -type f \
 	|grep '\.[ch]$' \
-	|sort -V \
+	|sort \
 	|xargs pcregrep -Mn "(?s)^asmlinkage\s+[\w\s]+\**sys_${1}\s*\(.*?\)" \
 	|sed -E 's/^[^:]+:[0-9]+:/&\n/';
 }
@@ -70,14 +70,14 @@ function grep_syscall()
 
 function grep_syscall_def()
 {
-	if ! [ -v 1 ]; then
+	if (($# != 1)); then
 		>&2 echo "Usage: ${FUNCNAME[0]} <syscall>";
 		return ${EX_USAGE};
 	fi
 
 	find * -type f \
 	|grep '\.c$' \
-	|sort -V \
+	|sort \
 	|xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\(${1},.*?^}" \
 	|sed -E 's/^[^:]+:[0-9]+:/&\n/';
 }
@@ -91,7 +91,7 @@ function grep_syscall_def()
 
 function man_section()
 {
-	if ! [ -v 2 ]; then
+	if (($# < 2)); then
 		>&2 echo "Usage: ${FUNCNAME[0]} <dir> <section>...";
 		return ${EX_USAGE};
 	fi
@@ -104,7 +104,7 @@ function man_section()
 	|xargs wc -l \
 	|grep -v -e '\b1 ' -e '\btotal\b' \
 	|awk '{ print $2 }' \
-	|sort -V \
+	|sort \
 	|while read -r manpage; do
 		cat \
 		<(<${manpage} sed -n '/^\.TH/,/^\.SH/{/^\.SH/!p}') \
@@ -125,7 +125,7 @@ function man_section()
 
 function man_lsfunc()
 {
-	if ! [ -v 1 ]; then
+	if (($# < 1)); then
 		>&2 echo "Usage: ${FUNCNAME[0]} <manpage|manNdir>...";
 		return ${EX_USAGE};
 	fi
@@ -147,7 +147,7 @@ function man_lsfunc()
 
 function man_lsvar()
 {
-	if ! [ -v 1 ]; then
+	if (($# < 1)); then
 		>&2 echo "Usage: ${FUNCNAME[0]} <manpage|manNdir>...";
 		return ${EX_USAGE};
 	fi
@@ -172,7 +172,7 @@ function man_lsvar()
 
 function pdfman()
 {
-	if ! [ -v 1 ]; then
+	if (($# != 1)); then
 		>&2 echo "Usage: ${FUNCNAME[0]} <man-page.n>";
 		return ${EX_USAGE};
 	fi;
@@ -209,14 +209,14 @@ function man_gitstaged()
 
 function grep_glibc_prototype()
 {
-	if ! [ -v 1 ]; then
+	if (($# != 1)); then
 		>&2 echo "Usage: ${FUNCNAME[0]} <func>";
 		return ${EX_USAGE};
 	fi
 
 	find * -type f \
 	|grep '\.h$' \
-	|sort -V \
+	|sort \
 	|xargs pcregrep -Mn \
 	  "(?s)^[\w[][\w\s(,)[:\]]+\s+\**${1}\s*\([\w\s(,)[\]*]+?(...)?\)[\w\s(,)[:\]]*;" \
 	|sed -E 's/^[^:]+:[0-9]+:/&\n/';
-- 
2.31.1




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux