Re: [Linuxcommand-discuss] shell printf function
Brought to you by:
bshotts
From: William S. <bs...@pa...> - 2003-03-28 20:05:18
|
In bash, the correct format would be: printf "# %-65s #\n" "$current_uptime" Don't use the parens. Also, you need to quote the argument since it contains embedded spaces. Lastly, you should include the "\n" in the format string since there is no carriage return if you don't explicitly specify it. ||||| William Shotts, Jr. (bshotts AT panix DOT com) ||||| Be a Linux Commander! Follow me to http://linuxcommand.org On Fri, 28 Mar 2003, Bram Mertens wrote: > On Sun, 2003-02-16 at 03:30, William Shotts wrote: > > Bram Mertens wrote: > [snip] > > > ---sig-general--- > > > #!/bin/bash > > > current_uptime=$(uptime) > > > current_kernel=$(uname -r) > > > current_machine=$(uname -m) > > > current_release="SuSE 8.1 Pro" > > > > > > echo -n '# '; echo -n $current_release; echo -n ' kernel '; echo -n > > > $current_kernel; echo -n ' '; echo -n $current_machine; echo ' 128MB RAM > > > #' > > > echo -n '# '; echo -n $current_uptime; echo ' #' > > > echo '</pre>' > > > ---end--- > [snip] > > bash contains a printf command that is mostly like the C/perl/etc > > function. Try "help printf" at the bash prompt. Failing that, many > > distributions have a printf program that can be called from scripts. > > Try "man printf" > > I can't seem to get this working, I've tried several variations of the > following but A always get the same error: > m8ram@linux:~> sig-general > # SuSE 8.1 Pro kernel 2.4.19-4GB i686 128MB RAM # > # 7:59pm up 11 days, 1:21, 6 users, load average: 2.18, 2.13, 2.10 # > /home/m8ram/bin/sig-general: line 9: syntax error near unexpected token > `"# %-65s #",' > /home/m8ram/bin/sig-general: line 9: `printf("# %-65s #", > curent_uptime)' > > I've tried to specify the variable as $current_uptime, > $(surrent_uptime), ($current_uptime),... > I've tried %c and %s, single quotes, double quotes... > > What is the right format? > > TIA > -- > # Mertens Bram "M8ram" <bra...@li...> Linux User #249103 # > # SuSE 8.1 Pro kernel 2.4.19-4GB i686 128MB RAM # > # 8:01pm up 11 days, 1:23, 6 users, load average: 2.59, 2.22, 2.13 # > > > > ------------------------------------------------------- > This SF.net email is sponsored by: > The Definitive IT and Networking Event. Be There! > NetWorld+Interop Las Vegas 2003 -- Register today! > http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en > _______________________________________________ > Linuxcommand-discuss mailing list > Lin...@li... > https://lists.sourceforge.net/lists/listinfo/linuxcommand-discuss > |