{ads}

Using the eval command in Linux to run variables as commands



July 08, 2022 at 02:01AM

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 that’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:

$ dt="TZ='Australia/Sydney' date"

You could then run it like this:

$ eval $dt

Thu Jul  7 06:32:14 AM AEST 2022

Doing that can save you the trouble of memorizing the date command syntax and specifying a time zone, but let’s look a little more closely at eval to see what else it can do for you.

To read this article in full, please click here



from Network World https://ift.tt/FlqZLBo

0 Response to "Using the eval command in Linux to run variables as commands"

Post a Comment

Article Top Ads

Central Ads Article 1

Middle Ads Article 2

Article Bottom Ads