[PATCH modular 11/13] build.sh: regroup script main line together

Cyril Brulebois kibi at debian.org
Thu Dec 30 14:02:19 PST 2010


Gaetan Nadon <memsize at videotron.ca> (29/12/2010):
> +# perform sanity checks on cmdline args which require arguments
> +# arguments:
> +#   $1 - the option being examined
> +#   $2 - the argument to the option
> +# returns:
> +#   if it returns, everything is good
> +#   otherwise it exit's
> +required_arg() {
> +    # preconds
> +    if [ X"$1" = X ]; then
> +	echo "internal required_arg() error, missing \$1 argument"
> +	exit 1
> +    fi
> +
> +    # check for an argument
> +    if [ X"$2" = X ]; then
> +	echo "the '$1' option is missing its required argument"
> +	echo ""
> +	usage
> +	exit 1
> +    fi
> +
> +    # does the argument look like an option?
> +    echo $2 | grep "^-" > /dev/null
> +    if [ $? -eq 0 ]; then
> +	echo "the argument '$2' of option '$1' looks like an option itself"
> +	echo ""
> +	usage
> +	exit 1
> +    fi
> +}

Can be written like this:

if ! echo $2 | grep -qs '^-'; then
  …
fi

Checking the -q/-s options in (GNU) grep's manpage, it seems to be
less portable than what I thought (but you can keep > /dev/null
instead).

Anyway that doesn't change the fact that you can check for the return
value directly in the if test, rather than using $? from the previous
command.

KiBi.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.x.org/archives/xorg-devel/attachments/20101230/59d9b9c0/attachment.pgp>


More information about the xorg-devel mailing list