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

Re: [PATCH] Replace "echo -n" with printf in shell scripts.

From
Eric Blake <ebb9@byu.net>
Date
Jan 16, 2007, 03:09 UTC
Message-ID
<45AC41F0.8090106@byu.net>
In-Reply-To
<7v1wlv1yeh.fsf@assigned-by-dhcp.cox.net>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Junio C Hamano on 1/15/2007 7:46 PM:
Show 5 quoted lines
>> -			name=$(echo -n "$f" | tr -c "A-Za-z0-9" ".")
>> +			name=$(printf "$f" | tr -c "A-Za-z0-9" ".")
> 
> This should almost be safe as no sane person would have a remote
> whose name is 'foo%s'...

Why not go all the way, and make it safe, regardless of embedded %, embedded \, or leading -?

name=$(printf -- %s "$f" | tr -c "A-Za-z0-9" ".")
- --
Don't work too hard, make some time for fun as well!
Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFrEHw84KuGfSFAYARAlH9AJ9q3atCpSVBTg0SVhZ4DQ9T7qiqEQCfe9D2 bGTfwnvW6uN1ky6ncWYgkgc= =P9t5 -----END PGP SIGNATURE-----

Previous: Jason RiedyNext: Horst H. von Brand
Message 4 of 11 in “Replace "echo -n" with printf in shell scripts.”
  1. Replace "echo -n" with printf in shell scripts.Jason Riedy, Jan 16, 2007
  2. Junio C HamanoJan 16, 2007
  3. Jason RiedyJan 16, 2007
  4. Eric BlakeJan 16, 2007
  5. Horst H. von BrandJan 17, 2007
  6. Junio C HamanoJan 17, 2007
  7. Brian GernhardtJan 17, 2007
  8. Julian PhillipsJan 17, 2007
  9. Horst H. von BrandJan 17, 2007
  10. Simon 'corecode' SchubertJan 18, 2007
  11. Junio C HamanoJan 18, 2007

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.