git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Update bash completions to prevent unbound variable errors.

From
Adeodato Simó <dato@net.com.org.es>
Date
Jan 12, 2009, 21:40 UTC
Message-ID
<20090112214052.GB24941@chistera.yi.org>
In-Reply-To
<496BA0E4.2040607@tedpavlic.com>
* Ted Pavlic [Mon, 12 Jan 2009 14:58:28 -0500]:

I don't know if this patch will go forward or not, but there are several instances of spurious ${x-}, eg.:

>  __gitdir ()
>  {
> -	if [ -z "$1" ]; then
> +	if [ -z "${1-}" ]; then
Given the above...
Show 7 quoted lines
> -	elif [ -d "$1/.git" ]; then
> -		echo "$1/.git"
> +	elif [ -d "${1-}/.git" ]; then
> +		echo "${1-}/.git"
>  	else
> -		echo "$1"
> +		echo "${1-}"

... this other hunk is redundant, because if [ -z "${1-}" ] fails, then $1 is surely set.

Show 5 quoted lines
>  __git_ps1 ()
>  {
>  	local g="$(git rev-parse --git-dir 2>/dev/null)"
> -	if [ -n "$g" ]; then
> +	if [ -n "${g-}" ]; then
Spurious, $g is always set here.
> @@ -111,8 +111,8 @@ __git_ps1 ()
> -		if [ -n "$1" ]; then
> +		if [ -n "${1-}" ]; then
This one is okay...
> -			printf "$1" "${b##refs/heads/}$r"
> +			printf "${1-}" "${b##refs/heads/}$r"
But this one is unnecessary, if [ -n "${1-}" ] succeeds, then $1 is set.
And so on.
-- 
Adeodato Simó                                     dato at net.com.org.es
Debian Developer                                  adeodato at debian.org
 
The true teacher defends his pupils against his own personal influence.
                -- Amos Bronson Alcott
Previous: Adeodato Simó
Message 14 of 14 in “Update bash completions to prevent unbound variable errors.”
  1. Update bash completions to prevent unbound variable errors.Ted Pavlic, Jan 12, 2009
  2. Boyd Stephen Smith Jr.Jan 12, 2009
  3. Adeodato SimóJan 12, 2009
  4. Boyd Stephen Smith Jr.Jan 12, 2009
  5. Shawn O. PearceJan 12, 2009
  6. Boyd Stephen Smith Jr.Jan 12, 2009
  7. Ted PavlicJan 12, 2009
  8. Ted PavlicJan 12, 2009
  9. Shawn O. PearceJan 12, 2009
  10. Ted PavlicJan 12, 2009
  11. Adeodato SimóJan 12, 2009
  12. Ted PavlicJan 12, 2009
  13. Adeodato SimóJan 12, 2009
  14. Adeodato SimóJan 12, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.