Skip to content

Using the eval command in Linux to run variables as commands

There are probably a lot of Linux users who have never encountered the eval command. In fact, it’s not really a “command”, but a bash built-in. If you ask “which eval”, bash is going to pretend it simply can’t find it, but if you type “eval date”, it will show you the current date and time in just the same way it would if you typed “date” by itself. Of course, this isn’t how you should be using eval since this example adds nothing to the output and requires you to type two words instead of one.

What eval was designed to do is quite different than running a command that doesn’t need any help. It’s meant to process the value of a variable as a command. For example, if you set up a variable that includes the command to display the current time in Sydney, Australia, it would probably look like this:

To read this article in full, please click here

Source:: Network World – Data Center