commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
No command substitution but subshell redirection
There is 1 alternative - vote for the best!
This version uses read instead of eval.
It's quite easy to capture the output of a command and assign it in a shell's variable:
But, what if we want to perform the same task with just one program invocation? Here comes the power of eval! date(1) outputs a string like "day=29; month=07; year=11" (notice the semicolons I added on purpose at date's custom output) which is a legal shell line. This like is then parsed and executed by the shell once again with the help of eval. Just setting 3 variables!
Inspired by LinuxJournal's column "Dave Taylor's Work the Shell".
If you can do better, submit your command here.
You must be signed in to comment.