“I believe this ‘paradoxicality’ equation to be unsolvable,” he says, pointing to the equation, E=9.87sin(2B)-7.53cos(B)-1.5sin(B), written on a blackboard. “Ergo, time travel is impossible. But I can’t quite prove it.”
So the humor here is that it's paradoxical to want to solve a single equation with two variables? Or am I being too geeky here? After all, the solution is *trivial*...
So you post a form to an iframe by pressing a submit button, and the iframe reloads with new dynamic content? And this is somehow AJAX? The whole interesting thing with AJAX is that you can interact with the web server while staying on the same page. You can type something into a search box, say, and the webserver sends you back some matching words in real time. Sure you could mimic the same thing with a POST and a results page, but that is exactly the paradigm that AJAX was supposed to replace.
You can check whether you're outputting to a terminal with test -t. If the output is not going to a terminal (say, to a pipe), you can print a plain vanilla string. You can output colour codes as straight ANSI escapes, or (probably better), use tput.
Example log function:
log() {
test -t 1 && { tput setf 4; cat; tput setf 7; } || cat
}
dmesg | log
This tests whether stdout is a terminal, and if so, prints the text in red. Otherwise (if stderr is redirected to a pipe or file) it prints the plain string.
MySQL replaces the password in the process table with a series of 'x' characters. Try it. The password is safe. While I agree that not passing anything on the commandline is a better solution, my MySQL version (5.0.67) does not support --defaults-file or --defaults-extra-file.
tar tf file.tar | while read file; do rm "$file"; done
This works because the entire line is read into $file, spaces and all.
Thanks, it's nothing I couldn't show a fella. Learnt a lot from my colleagues and from the O'Reilly 'Unix Power Tools' book. The Advanced Bash Shell-scripting Guide is pretty good (but chaotic) too.
The syntax filter here munged some of the examples, though. The here document example will not work as-is, because there should be two 'less-than' signs in front of the minus sign. The mysql_query function probably also won't work (can't bother to run a test), because the newline after the first bracket mysteriously disappeared. So best to loop up the concepts in some kind of reference manual.
I work as a Linux netadmin and system developer, so I do a lot of shell programming in (ba)sh. Here's some of the niftier things you can do to a shell script:
- Make colored output with shell escape sequences. Works especially well with red type for error messages, makes them really stand out.
- Use inline functions a lot. The great thing about them is that you can pipe to them and use them in all kinds of places. For instance, to do mysql queries:
mysql_query() {
}
echo 'SELECT * FROM accounts' | mysql_query
- "Here documents". For long MySQL sequences, something like the following (reusing the mysql_query function from above):
cat - EOF | mysql_query
SELECT bar
FROM foo
WHERE baz
EOF
This lets you easily format stdin for scripts and other programs. Also really useful for outputting HTML and stuff like that. Best thing is that variables are expanded inside the block.
- The || and && operators. Check if a file exists, remove if so, else complain:
[ -f
Also common in this form:
[ -x
- Making a "multithreaded" shellscript is also one of my favourites. Say, you want to start five virtual machines at the same time. Write a function that starts a vm, and call it a few times in a loop, backgrounding each instance with &, and saving their PIDs. Then have a "wait loop" that waits for the PIDs to exit the system (or for a timeout to occur).
- Proper argument handling with getopt. Have your script take "real" arguments in any order, just like real binaries.
This just scrapes the surface of the surface, of course. I learn new stuff every day.
lol , this is funny.
The hardest part of climbing the ladder of success is getting through the crowd at the bottom.