{"id":42276,"date":"2024-05-05T07:57:37","date_gmt":"2024-05-05T07:57:37","guid":{"rendered":"https:\/\/linuxsimply.com\/?p=42276"},"modified":"2024-05-06T08:33:56","modified_gmt":"2024-05-06T08:33:56","slug":"eval-command-in-linux","status":"publish","type":"post","link":"https:\/\/linuxsimply.com\/eval-command-in-linux\/","title":{"rendered":"The \u201ceval\u201d Command in Linux [4 Practical Examples]"},"content":{"rendered":"<p style=\"text-align: justify;\">The <strong>eval <\/strong>command is a built-in feature in Linux shells like Bash. If you need to execute the arguments as a shell command, you can use the eval command in Linux. This is useful for substituting variables, commands, and so on. In this article, I\u2019ll demonstrate the most common uses of the eval command with relevant examples.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Syntax_of_%E2%80%9Ceval%E2%80%9D_Command\" >Syntax of \u201ceval\u201d Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#4_Examples_of_Using_%E2%80%9Ceval%E2%80%9D_Command_in_Linux\" >4 Examples of Using \u201ceval\u201d Command in Linux<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#1_Using_%E2%80%9Ceval%E2%80%9D_Command_for_Variable_Substitution\" >1. Using \u201ceval\u201d Command for Variable Substitution<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Case_1_Single_Variable_Substitution\" >Case 1: Single Variable Substitution<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Case_2_Nested_Variable_Substitution\" >Case 2: Nested Variable Substitution<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Case_3_Environment_Variable_Substitution\" >Case 3: Environment Variable Substitution<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#2_Using_%E2%80%9Ceval%E2%80%9D_Command_for_Command_Substitution\" >2. Using \u201ceval\u201d Command for Command Substitution<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Case_1_Command_Substitution_Without_Option\" >Case 1: Command Substitution Without Option<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Case_2_Command_Substitution_With_Option\" >Case 2: Command Substitution With Option<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#3_Performing_Arithmetic_Operation_Using_%E2%80%9Ceval%E2%80%9D_Command\" >3. Performing Arithmetic Operation Using \u201ceval\u201d Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#4_Using_%E2%80%9Ceval%E2%80%9D_Command_for_Shell_Scripting\" >4. Using \u201ceval\u201d Command for Shell Scripting<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Alternatives_to_%E2%80%9Ceval%E2%80%9D_Command\" >Alternatives to \u201ceval\u201d Command<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Case_1_Using_%E2%80%9Csource%E2%80%9D_Command_as_an_Alternative_to_%E2%80%9Ceval%E2%80%9D_Command\" >Case 1: Using \u201csource\u201d Command as an Alternative to \u201ceval\u201d Command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Case_2_Using_Variable_Substitution_as_an_Alternative_to_%E2%80%9Ceval%E2%80%9D_Command\" >Case 2: Using Variable Substitution as an Alternative to \u201ceval\u201d Command<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#People_Also_Ask\" >People Also Ask<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Why_use_eval_in_bash\" >Why use eval in bash?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#What_is_the_difference_between_eval_and_exec_in_Linux\" >What is the difference between eval and exec in Linux?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#Why_the_eval_command_should_be_used_with_care\" >Why the eval command should be used with care?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Syntax_of_%E2%80%9Ceval%E2%80%9D_Command\"><\/span>Syntax of \u201ceval\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The syntax of the eval command is:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">eval [arg ...]<\/code><\/pre>\n<div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#e8f9fc;border-color:#ffffff;color:#333333;\">\n<p style=\"text-align: justify;\"><strong>Note: <\/strong>Everything inside square brackets is optional in this syntax. Three dots after the <strong>arg <\/strong>indicate that multiple values can be passed as arguments. On a different note, the <strong>eval <\/strong>command doesn\u2019t take any option.<\/div><\/div>\n<h2><span class=\"ez-toc-section\" id=\"4_Examples_of_Using_%E2%80%9Ceval%E2%80%9D_Command_in_Linux\"><\/span>4 Examples of Using \u201ceval\u201d Command in Linux<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Let\u2019s explore the use of the eval command with relevant examples:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Using_%E2%80%9Ceval%E2%80%9D_Command_for_Variable_Substitution\"><\/span>1. Using \u201ceval\u201d Command for Variable Substitution<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can use the eval command for variable substitution. Here are some examples:<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Case_1_Single_Variable_Substitution\"><\/span>Case 1: Single Variable Substitution<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">To substitute a single variable, you need to define a variable first, then use the eval command to substitute it. For example, let&#8217;s try out the following commands to store the value <strong>John<\/strong> in a variable named <strong>user1<\/strong> and later substitute it using eval:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">user1=John\neval echo $user1<\/code><\/pre>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-42287\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/2-variable-is-substituted.png\" alt=\"substituting a single variable using &quot;eval&quot; command in linux\" width=\"652\" height=\"187\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/2-variable-is-substituted.png 652w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/2-variable-is-substituted-300x86.png 300w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/><\/p>\n<p style=\"text-align: justify;\">From the image above, you can see the variable <strong>user1<\/strong> is substituted with its value <strong>John<\/strong> by using the eval command.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Case_2_Nested_Variable_Substitution\"><\/span>Case 2: Nested Variable Substitution<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">To substitute a nested variable, you can use the eval command. Here, a nested variable refers to assigning an already declared variable to another variable. For example, let\u2019s define two variables, <strong>user1<\/strong> and <strong>member1<\/strong>:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">user1=&quot;John Smith&quot;\nmember1=user1<\/code><\/pre>\n<p style=\"text-align: justify;\">Here, we&#8217;ve defined the user1 and later, assigned the <strong>user1<\/strong> to the <strong>member1<\/strong> variable. Now, call the <strong>member1<\/strong> variable:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">echo \\$$member1<\/code><\/pre>\n<p>This returns <strong>$user1<\/strong>. However, if we use the eval command at the beginning:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">eval echo \\$$member1<\/code><\/pre>\n<p>This <strong>eval <\/strong>command returns <strong>John Smith<\/strong>.<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-42288\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/3-variable-is-evaluated.png\" alt=\"nested variables are substituted\" width=\"699\" height=\"310\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/3-variable-is-evaluated.png 699w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/3-variable-is-evaluated-300x133.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/>In the above image, you can see that, while the <code class=\"\" data-line=\"\">echo \\$$member1<\/code> command line returns <strong>$user1<\/strong>, the <code class=\"\" data-line=\"\">eval echo \\$$member1<\/code> command line interprets the <strong>member1<\/strong> variable as <strong>user1<\/strong> and the <strong>user1<\/strong> variable stands for <strong>John Smith<\/strong>. So finally, the eval command returns <strong>John Smith<\/strong> which is the value of <strong>user1<\/strong>.<\/p>\n<p>From this example, you can better understand how the eval command works.<\/p>\n<div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#e8f9fc;border-color:#ffffff;color:#333333;\">\n<p style=\"text-align: justify;\"><strong>Note: <\/strong>While defining the variables, use double quotes around their value to avoid any unexpected error. For example, we&#8217;ve used double quotes while defining the variable user1=\u201dJohn Smith\u201d.<\/div><\/div>\n<h4><span class=\"ez-toc-section\" id=\"Case_3_Environment_Variable_Substitution\"><\/span>Case 3: Environment Variable Substitution<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>To get the value of an <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/variables\/types\/environment-variables\/#:~:text=In%20Linux%2C%20an%20environment%20variable%20is%20a%20dynamic%20named%20value%20that%20holds%20information%20about%20the%20system%E2%80%99s%20configuration%2C%20preferences%2C%20and%20behavior%2C%20which%20can%20be%20accessed%20by%20processes%20and%20programs%20running%20on%20the%20system.\" target=\"_blank\" rel=\"noopener\"><strong>environment variable<\/strong><\/a>, use only a dollar sign before the environment variable:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">var1=&#039;echo $USER&#039;\neval $var1<\/code><\/pre>\n<p>This returns the name of the current user.<\/p>\n<p style=\"text-align: justify;\">On the other hand, if you want to use the environmental variables as a string, then, you need to use a backslash and a dollar sign before the variable name:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">var2=&#039;echo \\$USER&#039;\neval $var2<\/code><\/pre>\n<p style=\"text-align: justify;\">These command lines consider the environment variable as a string and return the value as USER.<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-42290\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/5-environment-variable-is-returned.png\" alt=\"environment variable substitution using &quot;eval&quot; command \" width=\"693\" height=\"247\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/5-environment-variable-is-returned.png 693w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/5-environment-variable-is-returned-300x107.png 300w\" sizes=\"(max-width: 693px) 100vw, 693px\" \/><\/p>\n<p style=\"text-align: justify;\">The image above demonstrates scenarios where the value of the environment variable is returned and when the name of the environment variable is returned.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Using_%E2%80%9Ceval%E2%80%9D_Command_for_Command_Substitution\"><\/span>2. Using \u201ceval\u201d Command for Command Substitution<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">Command substitution in Linux allows you to use the output of one command as input or an argument for another command. You can use the <strong>eval <\/strong>command to substitute a command. Go through the examples to learn more about this:<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Case_1_Command_Substitution_Without_Option\"><\/span>Case 1: Command Substitution Without Option<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">To substitute a command without any option, you can use the eval command at the beginning. For example:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">echo &quot;\\$(date)&quot;<\/code><\/pre>\n<p style=\"text-align: justify;\">This command line considers $(date) as a string and returns it as $(date). Now if you want to get the date value instead while using the <a href=\"https:\/\/linuxsimply.com\/date-command-in-linux\/\" target=\"_blank\" rel=\"noopener\"><strong>date command<\/strong><\/a>, you can use the following command line:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">eval echo &quot;\\$(date)&quot;<\/code><\/pre>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42291\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/6-command-is-substituted.png\" alt=\"command is substituted without any option\" width=\"699\" height=\"238\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/6-command-is-substituted.png 699w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/6-command-is-substituted-300x102.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/p>\n<p style=\"text-align: justify;\">In the image above, you can see, the echo command returns the date command and the eval command evaluates the date command.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Case_2_Command_Substitution_With_Option\"><\/span>Case 2: Command Substitution With Option<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">To substitute a command with an option, you can use the eval command. For example, consider the following command with a long option:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">previousMonth=&#039;date --date=&quot;1 month ago&quot;&#039;<\/code><\/pre>\n<p style=\"text-align: justify;\">The previousMonth variable stores the date command with such an option that will return the date exactly one month ago. Now if you type the following command to get the date:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">$previousMonth<\/code><\/pre>\n<p style=\"text-align: justify;\">This shows an error. However, the following command line with the command eval, will do the job perfectly:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">eval $previousMonth<\/code><\/pre>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42292\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/7-command-along-with-its-option-is-substituted.png\" alt=\"command along with its option is substituted\" width=\"700\" height=\"270\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/7-command-along-with-its-option-is-substituted.png 700w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/7-command-along-with-its-option-is-substituted-300x116.png 300w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p style=\"text-align: justify;\">This image shows that the eval command evaluates the date command along with its option <code class=\"\" data-line=\"\">--date=&quot;1 month ago&quot;<\/code>. So, the <strong>eval<\/strong> command can be handy when dealing with commands that involve lengthy options.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Performing_Arithmetic_Operation_Using_%E2%80%9Ceval%E2%80%9D_Command\"><\/span>3. Performing Arithmetic Operation Using \u201ceval\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">To substitute the numeric variables, you can use the <strong>eval <\/strong>command. For instance, define two numeric variables days and hours, and use these variables to calculate another variable <strong>totalHours<\/strong>, which represents the product of the days and hours variables:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">days=7\nhours=24\ntotalHours=&#039;expr $days \\* $hours&#039;<\/code><\/pre>\n<p style=\"text-align: justify;\">Now use the <strong>eval <\/strong>command to display the value of the <strong>totalHours<\/strong> variable:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">eval $totalHours<\/code><\/pre>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42289\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/4-numeric-variable-is-substituted.png\" alt=\"performing arithmetic operation using &quot;eval&quot; command\" width=\"696\" height=\"276\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/4-numeric-variable-is-substituted.png 696w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/4-numeric-variable-is-substituted-300x119.png 300w\" sizes=\"(max-width: 696px) 100vw, 696px\" \/><\/p>\n<p style=\"text-align: justify;\">In the above image, you can see that the eval command has substituted the numeric variable with its numerical value <strong>168<\/strong>.<\/p>\n<div class=\"su-note\"  style=\"border-color:#cedfe2;\"><div class=\"su-note-inner su-u-clearfix su-u-trim\" style=\"background-color:#e8f9fc;border-color:#ffffff;color:#333333;\">\n<p style=\"text-align: justify;\"><strong>Note:<\/strong> You can also perform the arithmetic operation directly and display the result. For example, in this case, to get the product of the variables days and hours, you can use the following commands:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">totalHours=$(($days*$hours))\necho $totalHours<\/code><\/pre>\n<\/div><\/div>\n<h3><span class=\"ez-toc-section\" id=\"4_Using_%E2%80%9Ceval%E2%80%9D_Command_for_Shell_Scripting\"><\/span>4. Using \u201ceval\u201d Command for Shell Scripting<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can use the <strong>eval <\/strong>command in shell scripting. Let\u2019s demonstrate this with an example. First of all, open the nano editor to write a script named <strong>welcomeNote.sh<\/strong>:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">nano welcomeNote.sh<\/code><\/pre>\n<p>Here\u2019s an example of how to use the <strong>eval <\/strong>command for shell scripting:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">#!\/bin\/bash\n\nnote=&#039;echo &quot;Hello! This line is from the script.&quot;&#039;\neval $note<\/code><\/pre>\n<div class=\"su-box su-box-style-default\" id=\"\" style=\"border-color:#aeb0b3;border-radius:0px;max-width:none\"><div class=\"su-box-title\" style=\"background-color:#e1e3e6;color:#000000;border-top-left-radius:0px;border-top-right-radius:0px\">EXPLANATION<\/div><div class=\"su-box-content su-u-clearfix su-u-trim\" style=\"border-bottom-left-radius:0px;border-bottom-right-radius:0px\">\n<p style=\"text-align: justify;\">This script stores an <strong>echo <\/strong>command in a variable named <strong>note<\/strong>, and uses the <strong>eval <\/strong>command to execute the <strong>echo <\/strong>command.<\/div><\/div>\n<p>Now <a href=\"https:\/\/linuxsimply.com\/bash-scripting-tutorial\/basics\/executing\/make-file-executable\/#:~:text=Just%20use%20the%20syntax%2C%20%E2%80%9Cchmod,%E2%80%9Cchmod%20%2Bx%20filename%E2%80%9D.\" target=\"_blank\" rel=\"noopener\"><strong>execute<\/strong><\/a> the script welcomeNote.sh:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">welcomeNote.sh<\/code><\/pre>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42293\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/8-eval-command-in-bash-script.png\" alt=\"using &quot;eval&quot; command for shell scripting\" width=\"633\" height=\"190\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/8-eval-command-in-bash-script.png 633w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/8-eval-command-in-bash-script-300x90.png 300w\" sizes=\"(max-width: 633px) 100vw, 633px\" \/><\/p>\n<p style=\"text-align: justify;\">The image above contains the output of the script <strong>welcomeNote.sh<\/strong>. From the image, it is clear that the eval command has evaluated the variable note and worked properly in the script.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Alternatives_to_%E2%80%9Ceval%E2%80%9D_Command\"><\/span>Alternatives to \u201ceval\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">You can use some alternatives to the eval command. For example:<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Case_1_Using_%E2%80%9Csource%E2%80%9D_Command_as_an_Alternative_to_%E2%80%9Ceval%E2%80%9D_Command\"><\/span>Case 1: Using \u201csource\u201d Command as an Alternative to \u201ceval\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">As an alternative to the <strong>eval <\/strong>command, you can use the <a href=\"https:\/\/linuxsimply.com\/source-command-in-linux\/#Example_3_Executing_Command_Line_by_Line_from_a_File_in_Bash_Script_Using_the_source_Command_in_Linux:~:text=The%20source%20command%20in%20Linux%20executes%20commands%20from%20the%20file%20passed%20as%20an%20argument%20to%20it%20in%20the%20current%20shell%20environment.\" target=\"_blank\" rel=\"noopener\"><strong>source<\/strong><\/a> command. Type the following command line in the terminal to write a command in a script named welcome:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">echo &#039;echo Hello! This line is from the script.&#039; &gt; welcome.sh<\/code><\/pre>\n<p style=\"text-align: justify;\">Now, use the <strong>source <\/strong>command to run the command from the script \u201cwelcome.sh\u201d:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">source welcome.sh<\/code><\/pre>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-42294\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/9-source-command-as-the-alternative-to-the-eval-command.png\" alt=\"using &quot;source&quot; command as an alternative to &quot;eval&quot; command\" width=\"825\" height=\"155\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/9-source-command-as-the-alternative-to-the-eval-command.png 825w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/9-source-command-as-the-alternative-to-the-eval-command-300x56.png 300w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/9-source-command-as-the-alternative-to-the-eval-command-768x144.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/p>\n<p style=\"text-align: justify;\">The image shows that the source command executes the command of the welcome.sh script directly in the terminal.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Case_2_Using_Variable_Substitution_as_an_Alternative_to_%E2%80%9Ceval%E2%80%9D_Command\"><\/span>Case 2: Using Variable Substitution as an Alternative to \u201ceval\u201d Command<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p style=\"text-align: justify;\">If you are working on a relatively small project, you may consider directly using the variable substitution rather than using the eval command. For example, store a command in a variable named \u201ctoday\u201d:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">today=$(echo &#039;date&#039;)<\/code><\/pre>\n<p>Now directly use the variable substitution to get the date:<\/p>\n<pre><code class=\"language-bash\" data-line=\"\">$today<\/code><\/pre>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-42295 size-full\" src=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/10-command-substitution-as-an-alternative-to-the-eval-command.png\" alt=\"using variable substitution as an alternative to &quot;eval&quot; command\" width=\"696\" height=\"216\" srcset=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/10-command-substitution-as-an-alternative-to-the-eval-command.png 696w, https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/10-command-substitution-as-an-alternative-to-the-eval-command-300x93.png 300w\" sizes=\"(max-width: 696px) 100vw, 696px\" \/>In the above image, you can see, the command stored in the variable today is substituted.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">In this article, I\u2019ve demonstrated the eval command in Linux with some suitable examples. It\u00a0 is useful for substituting variables, commands, long options, and so on. Try out the useful examples yourself to get a hold of the eval command. I hope this article will be useful to you for that.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"People_Also_Ask\"><\/span>People Also Ask<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Why_use_eval_in_bash\"><\/span>Why use eval in bash?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">You can use the eval command in bash for various reasons. This includes the execution of other commands, substituting variables, and so on.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_is_the_difference_between_eval_and_exec_in_Linux\"><\/span>What is the difference between eval and exec in Linux?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The difference between the eval and exec commands is that the <strong>eval <\/strong>command evaluates and executes shell commands, while the <a href=\"https:\/\/linuxsimply.com\/exec-command-in-linux\/#:~:text=The%20exec%20command%20replaces%20the%20current%20terminal%20process%20with%20a%20new%20command.\" target=\"_blank\" rel=\"noopener\"><strong>exec<\/strong><\/a> command replaces the current shell process with a new command. The <strong>eval <\/strong>command passes its arguments as input to the shell and executes them.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Why_the_eval_command_should_be_used_with_care\"><\/span>Why the eval command should be used with care?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p style=\"text-align: justify;\">The eval command evaluates and executes its arguments as shell commands. Now if the argument of the <strong>eval <\/strong>command is a malicious command, then the harmful command will be executed by the shell and cause harm to the system. Also, using the eval command excessively may pose difficulty in debugging. Hence, we should use the eval command with care.<\/p>\n<p style=\"text-align: justify;\"><script type=\"application\/ld+json\">\n    {\n      \"@context\": \"https:\/\/schema.org\",\n      \"@type\": \"FAQPage\",\n      \"mainEntity\": [{\n                \"@type\": \"Question\",\n                \"name\": \"Why use eval in bash?\",\n                \"acceptedAnswer\": {\n              \"@type\": \"Answer\",\n              \"text\": \"You can use the eval command in bash for various reasons. This includes the execution of other commands, substituting variables, and so on.\"\n}\n},{\n                \"@type\": \"Question\",\n                \"name\": \"What is the difference between eval and exec in Linux?\",\n                \"acceptedAnswer\": {\n              \"@type\": \"Answer\",\n              \"text\": \"The difference between the eval and exec commands is that the eval command evaluates and executes shell commands, while the <a href=https:\/\/linuxsimply.com\/exec-command-in-linux\/#:~:text=The%20exec%20command%20replaces%20the%20current%20terminal%20process%20with%20a%20new%20command. target=_blank rel=noopener>exec<\/a> command replaces the current shell process with a new command. The eval command passes its arguments as input to the shell and executes them.\"\n}\n},{\n                \"@type\": \"Question\",\n                \"name\": \"Why the eval command should be used with care?\",\n                \"acceptedAnswer\": {\n              \"@type\": \"Answer\",\n              \"text\": \"The eval command evaluates and executes its arguments as shell commands. Now if the argument of the eval command is a malicious command, then the harmful command will be executed by the shell and cause harm to the system. Also, using the eval command excessively may pose difficulty in debugging. Hence, we should use the eval command with care.\"\n}\n}]\n}\n<\/script><\/p>\n<hr \/>\n<p><strong><span style=\"color: #000080; font-size: 18pt;\">Related Articles<\/span><\/strong><\/p>\n<ul>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201cecho\u201d Command in Linux [7 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/alias-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201calias\u201d Command in Linux [3 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/unalias-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201cunalias\u201d Command in Linux [3 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/exit-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201cexit\u201d Command in Linux [5 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/bash-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201cbash\u201d Command in Linux [5 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/clear-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201cclear\u201d Command in Linux [3 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/declare-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201cdeclare\u201d Command in Linux [7 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/export-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201cexport\u201d Command in Linux [8 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/source-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201csource\u201d Command in Linux [3 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/hash-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201chash\u201d Command in Linux [6 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/read-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201cread\u201d Command in Linux [8 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/set-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201cset\u201d Command in Linux [6 Practical Examples]<\/a><\/strong><\/li>\n<li><strong><a class=\"in-cell-link\" href=\"https:\/\/linuxsimply.com\/unset-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">The \u201cunset\u201d Command in Linux [2 Practical Examples]<\/a><\/strong><\/li>\n<\/ul>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-center kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;center&quot;,&quot;id&quot;:&quot;42276&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;The \u201ceval\u201d Command in Linux [4 Practical Examples]&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\">Rate this post<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>The eval command is a built-in feature in Linux shells like Bash. If you need to execute the arguments as &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"The \u201ceval\u201d Command in Linux [4 Practical Examples]\" class=\"read-more button\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/#more-42276\" aria-label=\"Read more about The \u201ceval\u201d Command in Linux [4 Practical Examples]\">Read more<\/a><\/p>\n","protected":false},"author":314916,"featured_media":42453,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[57],"class_list":["post-42276","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands","tag-shell-built-in-commands","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The \u201ceval\u201d Command in Linux [4 Practical Examples] - LinuxSimply<\/title>\n<meta name=\"description\" content=\"In this article, I&#039;ve demonstrated the eval command with practical examples. Read the syntaxes and try out the examples to master the command.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The \u201ceval\u201d Command in Linux [4 Practical Examples] - LinuxSimply\" \/>\n<meta property=\"og:description\" content=\"In this article, I&#039;ve demonstrated the eval command with practical examples. Read the syntaxes and try out the examples to master the command.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxsimply.com\/eval-command-in-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxSimply\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/hadiulbashar.alvi.9\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-05T07:57:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-06T08:33:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/1-eval-command-featured-image-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Hadi Ul Bashar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hadi Ul Bashar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/\"},\"author\":{\"name\":\"Hadi Ul Bashar\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/9c31ecf9e9697047ec9dae4e947747ea\"},\"headline\":\"The \u201ceval\u201d Command in Linux [4 Practical Examples]\",\"datePublished\":\"2024-05-05T07:57:37+00:00\",\"dateModified\":\"2024-05-06T08:33:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/\"},\"wordCount\":1439,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/1-eval-command-featured-image-1.png\",\"keywords\":[\"shell built-in commands\"],\"articleSection\":[\"Linux Commands\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/\",\"name\":\"The \u201ceval\u201d Command in Linux [4 Practical Examples] - LinuxSimply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/1-eval-command-featured-image-1.png\",\"datePublished\":\"2024-05-05T07:57:37+00:00\",\"dateModified\":\"2024-05-06T08:33:56+00:00\",\"description\":\"In this article, I've demonstrated the eval command with practical examples. Read the syntaxes and try out the examples to master the command.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/1-eval-command-featured-image-1.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/1-eval-command-featured-image-1.png\",\"width\":400,\"height\":400,\"caption\":\"eval command in linux featured image\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/eval-command-in-linux\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linuxsimply.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The \u201ceval\u201d Command in Linux [4 Practical Examples]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#website\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"name\":\"LinuxSimply\",\"description\":\"All About Linux\",\"publisher\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linuxsimply.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#organization\",\"name\":\"LinuxSimply\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/LinuxSimply-New-Logo-Without-Icon.png\",\"width\":355,\"height\":48,\"caption\":\"LinuxSimply\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/#\\\/schema\\\/person\\\/9c31ecf9e9697047ec9dae4e947747ea\",\"name\":\"Hadi Ul Bashar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/DSC07552-96x96.png\",\"url\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/DSC07552-96x96.png\",\"contentUrl\":\"https:\\\/\\\/linuxsimply.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/DSC07552-96x96.png\",\"caption\":\"Hadi Ul Bashar\"},\"description\":\"Hadi Ul Bashar holds a BSc degree in Biomedical Engineering from Bangladesh University of Engineering and Technology. In January 2023, Bashar joined Softeko as an Excel and VBA content developer. Since then, he has authored over 50 articles and created over 70 videos. Also, he has an interest in Linux. Currently, he is working as a Linux content developer executive. Here, he aims to create useful Linux content for its users. Reading books and travelling are his favourite pastimes. Read Full Bio\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hadiulbashar.alvi.9\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/hadi-ul-bashar-235ab214a\\\/\"],\"url\":\"https:\\\/\\\/linuxsimply.com\\\/author\\\/bashar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The \u201ceval\u201d Command in Linux [4 Practical Examples] - LinuxSimply","description":"In this article, I've demonstrated the eval command with practical examples. Read the syntaxes and try out the examples to master the command.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/linuxsimply.com\/eval-command-in-linux\/","og_locale":"en_US","og_type":"article","og_title":"The \u201ceval\u201d Command in Linux [4 Practical Examples] - LinuxSimply","og_description":"In this article, I've demonstrated the eval command with practical examples. Read the syntaxes and try out the examples to master the command.","og_url":"https:\/\/linuxsimply.com\/eval-command-in-linux\/","og_site_name":"LinuxSimply","article_author":"https:\/\/www.facebook.com\/hadiulbashar.alvi.9\/","article_published_time":"2024-05-05T07:57:37+00:00","article_modified_time":"2024-05-06T08:33:56+00:00","og_image":[{"width":400,"height":400,"url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/1-eval-command-featured-image-1.png","type":"image\/png"}],"author":"Hadi Ul Bashar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Hadi Ul Bashar","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxsimply.com\/eval-command-in-linux\/#article","isPartOf":{"@id":"https:\/\/linuxsimply.com\/eval-command-in-linux\/"},"author":{"name":"Hadi Ul Bashar","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/9c31ecf9e9697047ec9dae4e947747ea"},"headline":"The \u201ceval\u201d Command in Linux [4 Practical Examples]","datePublished":"2024-05-05T07:57:37+00:00","dateModified":"2024-05-06T08:33:56+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxsimply.com\/eval-command-in-linux\/"},"wordCount":1439,"commentCount":0,"publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"image":{"@id":"https:\/\/linuxsimply.com\/eval-command-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/1-eval-command-featured-image-1.png","keywords":["shell built-in commands"],"articleSection":["Linux Commands"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxsimply.com\/eval-command-in-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxsimply.com\/eval-command-in-linux\/","url":"https:\/\/linuxsimply.com\/eval-command-in-linux\/","name":"The \u201ceval\u201d Command in Linux [4 Practical Examples] - LinuxSimply","isPartOf":{"@id":"https:\/\/linuxsimply.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxsimply.com\/eval-command-in-linux\/#primaryimage"},"image":{"@id":"https:\/\/linuxsimply.com\/eval-command-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/1-eval-command-featured-image-1.png","datePublished":"2024-05-05T07:57:37+00:00","dateModified":"2024-05-06T08:33:56+00:00","description":"In this article, I've demonstrated the eval command with practical examples. Read the syntaxes and try out the examples to master the command.","breadcrumb":{"@id":"https:\/\/linuxsimply.com\/eval-command-in-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxsimply.com\/eval-command-in-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/eval-command-in-linux\/#primaryimage","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/1-eval-command-featured-image-1.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/05\/1-eval-command-featured-image-1.png","width":400,"height":400,"caption":"eval command in linux featured image"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxsimply.com\/eval-command-in-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxsimply.com\/"},{"@type":"ListItem","position":2,"name":"The \u201ceval\u201d Command in Linux [4 Practical Examples]"}]},{"@type":"WebSite","@id":"https:\/\/linuxsimply.com\/#website","url":"https:\/\/linuxsimply.com\/","name":"LinuxSimply","description":"All About Linux","publisher":{"@id":"https:\/\/linuxsimply.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxsimply.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linuxsimply.com\/#organization","name":"LinuxSimply","url":"https:\/\/linuxsimply.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2023\/09\/LinuxSimply-New-Logo-Without-Icon.png","width":355,"height":48,"caption":"LinuxSimply"},"image":{"@id":"https:\/\/linuxsimply.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/linuxsimply.com\/#\/schema\/person\/9c31ecf9e9697047ec9dae4e947747ea","name":"Hadi Ul Bashar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/04\/DSC07552-96x96.png","url":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/04\/DSC07552-96x96.png","contentUrl":"https:\/\/linuxsimply.com\/wp-content\/uploads\/2024\/04\/DSC07552-96x96.png","caption":"Hadi Ul Bashar"},"description":"Hadi Ul Bashar holds a BSc degree in Biomedical Engineering from Bangladesh University of Engineering and Technology. In January 2023, Bashar joined Softeko as an Excel and VBA content developer. Since then, he has authored over 50 articles and created over 70 videos. Also, he has an interest in Linux. Currently, he is working as a Linux content developer executive. Here, he aims to create useful Linux content for its users. Reading books and travelling are his favourite pastimes. Read Full Bio","sameAs":["https:\/\/www.facebook.com\/hadiulbashar.alvi.9\/","https:\/\/www.linkedin.com\/in\/hadi-ul-bashar-235ab214a\/"],"url":"https:\/\/linuxsimply.com\/author\/bashar\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/42276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/users\/314916"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/comments?post=42276"}],"version-history":[{"count":0,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/posts\/42276\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media\/42453"}],"wp:attachment":[{"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/media?parent=42276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/categories?post=42276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxsimply.com\/wp-json\/wp\/v2\/tags?post=42276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}