Friday, July 31, 2009

Unix/Linux doit program?

What commands would I need to write a program 'doit' that takes another Unix/Linux command as an argument and executes that command. For example executing





doit cat /etc/motd





would invoke the cat command on the file /etc/motd which will print the current "message of the day".





Any help appreciated!

Unix/Linux doit program?
Most shell interpreters don't *need* a 'doit' program - just saying 'cat /etc/motd' is sufficient But if you feel the need to do it the hard way (at the expense of a few extra fork/exec pairs you'd not have done the easy way), this should work:





/bin/sh -c "/bin/cat /etc/motd"


No comments:

Post a Comment