as i write more and more code i always block at managing output... either writing to standard out, writing to files via std out (log, temp file, etc). Don't get me wrong 99% of the time it DOES the job but maybe there is more efficient.
I'm writing a small script to help production use DNS dynamic updates (named.conf 400 lines with 300 zones so i can't fuckup) and main function goes like this:
As you can see i use echo's to std out and fd7 and printf.
I could always use a variable to my long line to make my code tidier but my main question is... is there ANY advantages to using one or another?
Is it a question of background as printf users usually means they did C?
I didn't use any:
As i would have to do one block for each occurences.
I also didn't start to touch logging... is there a definate standard in the coding community for the use of /* insert best coding practice for script logging */ ?
Well, echo sometimes does odd things on certain shells -- some expand escape sequences, some don't, some support options, some don't -- but printf "%s" "string" is pretty much guaranteed the same everywhere. If you know you'll always be using the "right" shell it doesn't really matter.
What goes wrong 1% of the time? 99% success rate is terrific for an exam, but horrible for a program.
I don't know if it'll be faster but it'll be simpler to let echo print to stdout than to redirect into &7 99 times:
As for logging, data belongs in stdout, human-readable errors belong in stderr, don't mix the two.
Hello,
For some reason i dont remember, i currently believe (but beeing unsure) that printf is available on more diffrent systems (unix, bsd, linux, ??) than echo is.
Could someone please enlighten me, whether this is true or not?
Thank you
PS:
I just found pages about the diffrences of... (3 Replies)
Hello
I want to check whether certain arguments were passed to the script, and when those are, not doing a log entry.
If those arguments are not passed, always do a log entry (*new call*).
What currently i have is this:
echo "${@}"|grep -q \\- || \
tui-log -e "$LOG" "\r---- New call $$... (4 Replies)
Hi All;
I try to create a excel like table with headers and some fields containing values, other long and complex mathematic formulas.
I have some header like : Name Formula Value True/False
Under name column, they are some formula names, formula column some long mathematic formulas... (9 Replies)
Legends,
I want to send the output to a webpage after execution of script.
the webpage layout will be something like below
HOSTNAME at <TIME>
--------------------
ProcessName1 <some text>
ProcessName2 <some text>
.....
.....
Pls help how i will approach... (1 Reply)
This may be little confusing. I have Script1, which pulls data from the system and creates another script(lets say script2). While I run script1 I need to add printf/echo statements for script2, so that when I run script2 I see those statement.
eg: script1 765
printf " display frame-$1 timeoffset... (2 Replies)
printf "%X\n" "A"
41
printf "%X\n" "2"
2
Expected 32 (not 2).
Is there a "printf" which will output the hexadecimal value of a numeric character? (9 Replies)
#!/usr/bin/ksh
var1="Hi World"
var2="Morning"
var3=$(echo "$var1" \n "$var2")
echo $var3
var3=$(printf "$var1 \n $var2")
echo $var3
Output
Any way to get
in my $var3 ? (7 Replies)
Hi ,
I wonder if in java I can pipe the below output of the printf into a variable:
System.out.printf(" This is a test %s\n", myVariable);
I want to keep the output of the printf command to create my history array.
Thanks. (2 Replies)
I want to print a colored line using bash. I want to print:
Smtp status
where "Smtp status" will be in yellow and will be in green.
Thanks. (2 Replies)
#include <stdio.h>
#include <math.h>
// this function calculates the volume of a Cylinder
int main(void)
{
int r; // radius
int h; // height
double M_PI; // pi
int pOne = pow (r, 2);
// get user input of radius and height
printf ("Enter your... (3 Replies)