<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Bash shell script tip: Run commands from a variable</title> <atom:link href="http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html/feed" rel="self" type="application/rss+xml" /><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html</link> <description>This is a Linux sys admin journal by Vivek about sys admin work, Linux tips &#38; tricks, hacks, news and more.</description> <lastBuildDate>Fri, 10 Feb 2012 20:37:43 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Petridish</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-178949</link> <dc:creator>Petridish</dc:creator> <pubDate>Wed, 25 Jan 2012 15:53:11 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-178949</guid> <description>I&#039;m a bit new to linux scripting, but I come from a programming background (c/c++). Out of curiosity, is there a different scripting language besides bash? The syntax is horrible, and I find it incredibly difficult to use.</description> <content:encoded><![CDATA[<p>I&#8217;m a bit new to linux scripting, but I come from a programming background (c/c++). Out of curiosity, is there a different scripting language besides bash? The syntax is horrible, and I find it incredibly difficult to use.</p> ]]></content:encoded> </item> <item><title>By: Rhongomiant</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-175719</link> <dc:creator>Rhongomiant</dc:creator> <pubDate>Thu, 17 Nov 2011 14:40:38 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-175719</guid> <description>dev,
cmd=`echo $line &#124; awk -F ‘;’ ‘{print $1}’`
count=`$cmd`
The variable cmd is storing the results of a command because you have the command encapsulated by backticks ``. Based on this information it seems like you are doubling your work. I would modify as follows.
cmd=`echo $line &#124; awk -F ‘;’ ‘{print $1}’`
count=&quot;$cmd&quot;
or
count=`echo $line &#124; awk -F ‘;’ ‘{print $1}’`
If you really need it setup this way, use double or single quotes to encapsulate the command defined by cmd.
cmd=&quot;echo $line &#124; awk -F ‘;’ ‘{print $1}’&quot;
I have not had luck storing commands that contain awk in a variable and calling it later. I usually use a function.
cmd () {
echo $line &#124; awk -F ‘;’ ‘{print $1}’
}
count=`cmd`</description> <content:encoded><![CDATA[<p>dev,</p><p>cmd=`echo $line | awk -F ‘;’ ‘{print $1}’`<br
/> count=`$cmd`</p><p>The variable cmd is storing the results of a command because you have the command encapsulated by backticks &#8220;. Based on this information it seems like you are doubling your work. I would modify as follows.</p><p>cmd=`echo $line | awk -F ‘;’ ‘{print $1}’`<br
/> count=&#8221;$cmd&#8221;</p><p>or</p><p>count=`echo $line | awk -F ‘;’ ‘{print $1}’`</p><p>If you really need it setup this way, use double or single quotes to encapsulate the command defined by cmd.</p><p>cmd=&#8221;echo $line | awk -F ‘;’ ‘{print $1}’&#8221;</p><p>I have not had luck storing commands that contain awk in a variable and calling it later. I usually use a function.</p><p>cmd () {<br
/> echo $line | awk -F ‘;’ ‘{print $1}’<br
/> }</p><p>count=`cmd`</p> ]]></content:encoded> </item> <item><title>By: samira</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-174571</link> <dc:creator>samira</dc:creator> <pubDate>Sun, 02 Oct 2011 18:34:49 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-174571</guid> <description>Hanish May 17, 2010
Hi investigated and eval did a trick.
CMD=’ps -elf&#124;grep vnc’
eval $CMD
Thanks to all
--------------------------
thankss soooo muccchhhhhhhh it is workeed</description> <content:encoded><![CDATA[<p>Hanish May 17, 2010<br
/> Hi investigated and eval did a trick.</p><p>CMD=’ps -elf|grep vnc’<br
/> eval $CMD</p><p>Thanks to all</p><p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br
/> thankss soooo muccchhhhhhhh it is workeed</p> ]]></content:encoded> </item> <item><title>By: dev</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-171253</link> <dc:creator>dev</dc:creator> <pubDate>Tue, 10 May 2011 17:58:05 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-171253</guid> <description>Hanish,
You did a great investigation man. My problem also solved
by giving like this count =`eval $cmd`
Thanks a lot hanish</description> <content:encoded><![CDATA[<p>Hanish,</p><p>You did a great investigation man. My problem also solved</p><p>by giving like this count =`eval $cmd`</p><p>Thanks a lot hanish</p> ]]></content:encoded> </item> <item><title>By: dev</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-171252</link> <dc:creator>dev</dc:creator> <pubDate>Tue, 10 May 2011 17:51:04 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-171252</guid> <description>Hi,
I am trying to execute some list of commands.So,I have added my commands inside a csv file.I am trying to read that command and execute the command and store the result of the command in the variable.
cmd=`echo $line &#124; awk -F &#039;;&#039; &#039;{print $1}&#039;`
After this &quot;cmd&quot; gets the value like &quot;cat filename &#124; wc -l &quot;
I am trying to store in a variable like this
count=`$cmd`.
Since there is a pipe i am getting error.
Can some one help me on this</description> <content:encoded><![CDATA[<p>Hi,</p><p>I am trying to execute some list of commands.So,I have added my commands inside a csv file.I am trying to read that command and execute the command and store the result of the command in the variable.</p><p>cmd=`echo $line | awk -F &#8216;;&#8217; &#8216;{print $1}&#8217;`<br
/> After this &#8220;cmd&#8221; gets the value like &#8220;cat filename | wc -l &#8221;</p><p>I am trying to store in a variable like this<br
/> count=`$cmd`.</p><p>Since there is a pipe i am getting error.<br
/> Can some one help me on this</p> ]]></content:encoded> </item> <item><title>By: Hanish</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-156058</link> <dc:creator>Hanish</dc:creator> <pubDate>Mon, 17 May 2010 16:00:32 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-156058</guid> <description>Hi investigated and eval did a trick.
CMD=&#039;ps -elf&#124;grep vnc&#039;
eval $CMD
Thanks to all</description> <content:encoded><![CDATA[<p>Hi investigated and eval did a trick.</p><p>CMD=&#8217;ps -elf|grep vnc&#8217;<br
/> eval $CMD</p><p>Thanks to all</p> ]]></content:encoded> </item> <item><title>By: Hanish</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-156055</link> <dc:creator>Hanish</dc:creator> <pubDate>Mon, 17 May 2010 14:39:47 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-156055</guid> <description>if I give a PIPE to a command then it does not work like
CMD=&#039;ps -ef&#124;grep vnc&#039;
Help me out...</description> <content:encoded><![CDATA[<p>if I give a PIPE to a command then it does not work like</p><p>CMD=&#8217;ps -ef|grep vnc&#8217;</p><p>Help me out&#8230;</p> ]]></content:encoded> </item> <item><title>By: kalem</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-152276</link> <dc:creator>kalem</dc:creator> <pubDate>Mon, 14 Dec 2009 11:30:46 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-152276</guid> <description>hi, i am trying to make a precess to run by itself whenever a  media is plugged.
the process finds and eliminate (deletes) programs ,viruses .
since i  use UNIX/lunix , these programs don&#039;t run on my machine.
can any one say some ?
thanks in advance</description> <content:encoded><![CDATA[<p>hi, i am trying to make a precess to run by itself whenever a  media is plugged.<br
/> the process finds and eliminate (deletes) programs ,viruses .<br
/> since i  use UNIX/lunix , these programs don&#8217;t run on my machine.<br
/> can any one say some ?<br
/> thanks in advance</p> ]]></content:encoded> </item> <item><title>By: pavium</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-148255</link> <dc:creator>pavium</dc:creator> <pubDate>Wed, 22 Apr 2009 13:26:09 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-148255</guid> <description>It may be slightly more &lt;em&gt;clever&lt;/em&gt; to use variables this way, but what are we sacrificing? READABILITY.
You&#039;ll be sorry when to look at the script a few months from now.</description> <content:encoded><![CDATA[<p>It may be slightly more <em>clever</em> to use variables this way, but what are we sacrificing? READABILITY.</p><p>You&#8217;ll be sorry when to look at the script a few months from now.</p> ]]></content:encoded> </item> <item><title>By: charusrinivasan</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-147945</link> <dc:creator>charusrinivasan</dc:creator> <pubDate>Thu, 02 Apr 2009 13:01:24 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-147945</guid> <description>hai i want a  example linux program for case statement</description> <content:encoded><![CDATA[<p>hai i want a  example linux program for case statement</p> ]]></content:encoded> </item> <item><title>By: Finnbarr Murphy</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-143266</link> <dc:creator>Finnbarr Murphy</dc:creator> <pubDate>Mon, 24 Mar 2008 10:02:18 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-143266</guid> <description>This is not just a bash feature as you imply. $CMD works with Korn shell and most other shells.</description> <content:encoded><![CDATA[<p>This is not just a bash feature as you imply. $CMD works with Korn shell and most other shells.</p> ]]></content:encoded> </item> <item><title>By: corex</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-142105</link> <dc:creator>corex</dc:creator> <pubDate>Sat, 08 Dec 2007 14:32:41 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-142105</guid> <description>I experienced another problem.
If I call script files, input methods (read )  are ignored.
&lt;code&gt;
find /media/private -iname &quot;*.bash&quot; &#124; while read file
do
echo &quot;Executing:  $file&quot;
$file -m
if [ &quot;$?&quot; -ne 0 ]
then
echo &quot;Error executing $file&quot;
exit 1
fi
echo &quot;done&quot;
&lt;/code&gt;</description> <content:encoded><![CDATA[<p>I experienced another problem.<br
/> If I call script files, input methods (read )  are ignored.<br
/> <code><br
/> find /media/private -iname "*.bash" | while read file<br
/> do<br
/> echo "Executing:  $file"<br
/> $file -m<br
/> if [ "$?" -ne 0 ]<br
/> then<br
/> echo "Error executing $file"<br
/> exit 1<br
/> fi</p><p>echo "done"<br
/> </code></p> ]]></content:encoded> </item> <item><title>By: raihan</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-141167</link> <dc:creator>raihan</dc:creator> <pubDate>Sat, 22 Sep 2007 12:35:50 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-141167</guid> <description>can you guys please send me linux shell script commands for  backup documents home folder, i need it
very badly  because i need to submit it on 24/9/07 to my teacher..please any one kindly send me this..
my e-mail address raihan_alam@hotmail.com</description> <content:encoded><![CDATA[<p>can you guys please send me linux shell script commands for  backup documents home folder, i need it<br
/> very badly  because i need to submit it on 24/9/07 to my teacher..please any one kindly send me this..<br
/> my e-mail address <a
href="mailto:raihan_alam@hotmail.com">raihan_alam@hotmail.com</a></p> ]]></content:encoded> </item> <item><title>By: Mahesh</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-132005</link> <dc:creator>Mahesh</dc:creator> <pubDate>Fri, 04 May 2007 06:54:44 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-132005</guid> <description>Hi
I want to take tar-backup of user home folders on RH9 Linux.
My short script is as follows :
#!/bin/bash
#pwd
cd /home
tar cvzf /backup/archive/usr1-`date +%C%y%m%d`.tar.gz usr1
tar cvzf /backup/archive/usr2-`date +%C%y%m%d`.tar.gz usr2
.
.
So On !!!!!!!!!
If i am running this script from cmd , it works fine. But If i cron the job it stops aborted on 2nd directory itself with half-completed tar file.
How to solve this problem? I am not so novice in Linux. Pls help.
Regards /Mahesh</description> <content:encoded><![CDATA[<p>Hi</p><p>I want to take tar-backup of user home folders on RH9 Linux.</p><p>My short script is as follows :</p><p>#!/bin/bash<br
/> #pwd<br
/> cd /home<br
/> tar cvzf /backup/archive/usr1-`date +%C%y%m%d`.tar.gz usr1<br
/> tar cvzf /backup/archive/usr2-`date +%C%y%m%d`.tar.gz usr2<br
/> .<br
/> .<br
/> So On !!!!!!!!!</p><p> If i am running this script from cmd , it works fine. But If i cron the job it stops aborted on 2nd directory itself with half-completed tar file.<br
/> How to solve this problem? I am not so novice in Linux. Pls help.</p><p>Regards /Mahesh</p> ]]></content:encoded> </item> <item><title>By: Bruno</title><link>http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-122234</link> <dc:creator>Bruno</dc:creator> <pubDate>Tue, 24 Apr 2007 07:41:45 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/tips/howto-running-commands-from-a-variable.html#comment-122234</guid> <description>It would be nice to write just 2 lines about the way it works : (condition-A &amp;&amp; condition-B) : bash evaluate condition-B only if condition-A is true. If condition-A is false, the result is FALSE anyway and bash doesn&#039;t need to evaluate condition-B. Then it goes thru all the &#124;&#124; conditions.
Or point to a page that explain this.
Anyway, it is very nice to be able to read these tips on a regular basis.
Thanks</description> <content:encoded><![CDATA[<p>It would be nice to write just 2 lines about the way it works : (condition-A &amp;&amp; condition-B) : bash evaluate condition-B only if condition-A is true. If condition-A is false, the result is FALSE anyway and bash doesn&#8217;t need to evaluate condition-B. Then it goes thru all the || conditions.<br
/> Or point to a page that explain this.<br
/> Anyway, it is very nice to be able to read these tips on a regular basis.<br
/> Thanks</p> ]]></content:encoded> </item> </channel> </rss>
