From: Sidney Lambe on 1 Feb 2010 04:45 On comp.unix.shell, Ivan Shmakov <ivan(a)main.uusia.org> wrote: >>>>>> "SL" == Sidney Lambe <sidneylambe(a)nospam.invalid> writes: > > [...] > > SL> Bash: > > SL> (( $aa + $bb = cc }} > > SL> if [ "$cc" -lt 10 ] > > SL> then cc=$(echo "$cc" | sed 's/.*/0&/') > > SL> fi > > SL> There are surely better ways to do it. > > E. g., instead of using Sed, one could simply do: > > ... > then cc=0"$cc" > ... > > Or, even more concise: > > cc=$(($aa + $bb)) > [ "$cc" -lt 10 ] && cc=0"$cc" > > But, as mentioned elsewhere in this group, it's better to use > `printf' for the formatting tasks like this. > Thanks, Ivan. That's much better. Printf has always baffled me. The man page is pathetically inadequate. As is the entry in man bash. There's a lot of printf examples in the advanced shellscripting guide. I guess I better start playing with them. It would improve the aesthetics/readability of the output of my scripts, I think. Sid
From: Ivan Shmakov on 1 Feb 2010 05:28 >>>>> "SL" == Sidney Lambe <sidneylambe(a)nospam.invalid> writes: >>>>> "IS" == Ivan Shmakov <ivan(a)main.uusia.org> wrote: >>>>> "SL" == Sidney Lambe <sidneylambe(a)nospam.invalid> writes: [...] SL> then cc=$(echo "$cc" | sed 's/.*/0&/') [...] SL> There are surely better ways to do it. IS> E. g., instead of using Sed, one could simply do: [...] IS> Or, even more concise: IS> cc=$(($aa + $bb)) IS> [ "$cc" -lt 10 ] && cc=0"$cc" IS> But, as mentioned elsewhere in this group, it's better to use IS> `printf' for the formatting tasks like this. SL> Thanks, Ivan. That's much better. Printf has always baffled me. The SL> man page is pathetically inadequate. As is the entry in man bash. The documentation for the GNU project's tools is maintained in the Texinfo format. Please consider looking at, e. g.: http://www.gnu.org/software/coreutils/manual/html_node/printf-invocation.html http://www.gnu.org/software/coreutils/manual/libc/Output-Conversion-Syntax.html The latter is also at: http://www.gnu.org/software/libc/manual/html_node/Output-Conversion-Syntax.html SL> There's a lot of printf examples in the advanced shellscripting SL> guide. I guess I better start playing with them. It would improve SL> the aesthetics/readability of the output of my scripts, I think. -- FSF associate member #7257
From: Sidney Lambe on 1 Feb 2010 07:53 On comp.unix.shell, Bit Twister <BitTwister(a)mouse-potato.com> wrote: > On 1 Feb 2010 09:16:38 +0100, Sidney Lambe wrote: > >> Okay, I think I've got it. But what if a=333? > > For crying out loud, you seemed to have proclaimed yourself > mister cli and run no gui desktop manager, just enter > > a=333 printf "%02d\n" "$a" > > at the command line prompt and see what happens. > > For crying out loud: If you had read the thread before running your mouth, you would have seen that I obviously did just that. Bit Twister often shows up when I post something and tries to harass me. He's one of these guys who can't handle it when someone disagrees with them and refuses to be bullied. Stupid punks like this are a fact of life on the Useenet. Background noise. Sid
From: Sidney Lambe on 1 Feb 2010 07:53 On comp.unix.shell, Ivan Shmakov <ivan(a)main.uusia.org> wrote: >>>>>> "SL" == Sidney Lambe <sidneylambe(a)nospam.invalid> writes: >>>>>> "IS" == Ivan Shmakov <ivan(a)main.uusia.org> wrote: >>>>>> "SL" == Sidney Lambe <sidneylambe(a)nospam.invalid> writes: > > [...] > > SL> then cc=$(echo "$cc" | sed 's/.*/0&/') > > [...] > > SL> There are surely better ways to do it. > > IS> E. g., instead of using Sed, one could simply do: > > [...] > > IS> Or, even more concise: > > IS> cc=$(($aa + $bb)) > > IS> [ "$cc" -lt 10 ] && cc=0"$cc" > > IS> But, as mentioned elsewhere in this group, it's better to use > IS> `printf' for the formatting tasks like this. > > SL> Thanks, Ivan. That's much better. Printf has always baffled me. The > SL> man page is pathetically inadequate. As is the entry in man bash. > > The documentation for the GNU project's tools is maintained in > the Texinfo format. Please consider looking at, e. g.: > > http://www.gnu.org/software/coreutils/manual/html_node/printf-invocation.html > http://www.gnu.org/software/coreutils/manual/libc/Output-Conversion-Syntax.html > > The latter is also at: > > http://www.gnu.org/software/libc/manual/html_node/Output-Conversion-Syntax.html > > SL> There's a lot of printf examples in the advanced shellscripting > SL> guide. I guess I better start playing with them. It would improve > SL> the aesthetics/readability of the output of my scripts, I think. > > -- > FSF associate member #7257 Thank again, Ivan. I'll acquire those docs and any others that I should have here. Sid
From: Seebs on 1 Feb 2010 16:59 On 2010-02-01, Ivan Shmakov <ivan(a)main.uusia.org> wrote: > The documentation for the GNU project's tools is maintained in > the Texinfo format. Which violates the principle of least surprise to an astonishing extent. The "info" browser remains pathologically hard to use if you happen not to be primarily used to emacs, the HTML forms are annoying at best in a plain text terminal, and they are not where experienced UNIX users look for documentation. On paper, it must have sounded great to invent a shiny new documentation format which corrected all sorts of deficiencies. In practice, it means that there's no simple command you can type to get "the complete text of the manual for program X" in a searchable and usable form, and that if you do the thing that everyone has told you to do every time you have asked a UNIX question in your entire life, you inexplicably get shoddy and half-baked documentation. It really is a very bad decision. That said, the printf command is pretty decently documented on many systems, and it's nearly self-explanatory, except for the inexplicably stupid behavior of %c. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
|
Next
|
Last
Pages: 1 2 3 Prev: Delete Chinese characters from the filenames. Next: Remove certain characters in a filename |