<?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 tips: if -e wildcard file check =&gt; [: too many arguments</title> <atom:link href="http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/feed/" rel="self" type="application/rss+xml" /><link>http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/</link> <description>The Journal Of A Linux Sysadmin</description> <lastBuildDate>Wed, 08 Feb 2012 13:08:17 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3</generator> <item><title>By: kju</title><link>http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/comment-page-1/#comment-193882</link> <dc:creator>kju</dc:creator> <pubDate>Tue, 24 Jan 2012 16:47:52 +0000</pubDate> <guid
isPermaLink="false">http://www.ducea.com/?p=672#comment-193882</guid> <description>Please note that my solution is somewhat similar to the one of Trevor. His solution however has a bug which occurs if the testpattern is for example &quot;bla*&quot; and a file literally named &quot;bla*&quot; (which is legal) exists. My solution handles this fine.</description> <content:encoded><![CDATA[<p>Please note that my solution is somewhat similar to the one of Trevor. His solution however has a bug which occurs if the testpattern is for example &#8220;bla*&#8221; and a file literally named &#8220;bla*&#8221; (which is legal) exists. My solution handles this fine.</p> ]]></content:encoded> </item> <item><title>By: kju</title><link>http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/comment-page-1/#comment-193881</link> <dc:creator>kju</dc:creator> <pubDate>Tue, 24 Jan 2012 16:45:58 +0000</pubDate> <guid
isPermaLink="false">http://www.ducea.com/?p=672#comment-193881</guid> <description>Just do it this way:testpattern=whatever*
ok=0
for tmp in $testpattern
do
if [ -e $tmp ] ; then ok=1 ; fi
break
doneif [ $ok -eq 1 ]
then
echo &quot;Matches&quot;
else
echo &quot;Does not match&quot;
fi</description> <content:encoded><![CDATA[<p>Just do it this way:</p><p>testpattern=whatever*<br
/> ok=0<br
/> for tmp in $testpattern<br
/> do<br
/> if [ -e $tmp ] ; then ok=1 ; fi<br
/> break<br
/> done</p><p>if [ $ok -eq 1 ]<br
/> then<br
/> echo &#8220;Matches&#8221;<br
/> else<br
/> echo &#8220;Does not match&#8221;<br
/> fi</p> ]]></content:encoded> </item> <item><title>By: Isaac</title><link>http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/comment-page-1/#comment-193796</link> <dc:creator>Isaac</dc:creator> <pubDate>Tue, 20 Dec 2011 18:48:10 +0000</pubDate> <guid
isPermaLink="false">http://www.ducea.com/?p=672#comment-193796</guid> <description>Thanks Matt Simmons! the for loop made the most sense and worked for me.All of the above was useful information, but I can&#039;t see how anything  beats the for loop, I was doing for files in `ls filename.0*` and I just needed to modify it so it didn&#039;t use ls to get the file list. Not sure why I started out using ls, but I&#039;m guessing I had a syntax issue until I used your example.</description> <content:encoded><![CDATA[<p>Thanks Matt Simmons! the for loop made the most sense and worked for me.</p><p>All of the above was useful information, but I can&#8217;t see how anything  beats the for loop, I was doing for files in `ls filename.0*` and I just needed to modify it so it didn&#8217;t use ls to get the file list. Not sure why I started out using ls, but I&#8217;m guessing I had a syntax issue until I used your example.</p> ]]></content:encoded> </item> <item><title>By: Stephen</title><link>http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/comment-page-1/#comment-193602</link> <dc:creator>Stephen</dc:creator> <pubDate>Mon, 10 Oct 2011 04:34:35 +0000</pubDate> <guid
isPermaLink="false">http://www.ducea.com/?p=672#comment-193602</guid> <description>WAYYYYYY too complicated, all of you.If what you want is reasonably terse script that works entirely with bash builtins and doesn&#039;t fail unless bash can&#039;t expand the glob without blowing out its command line buffer, use nullglob in a subshell:if test -n &quot;$(shopt -s nullglob; cd /tmp; echo *.cache)&quot;
then
&#160;&#160;&#160;&#160;echo Cache files exist
else
&#160;&#160;&#160;&#160;echo No cache files
fiIf you&#039;d rather know that your script will always do the right thing, you don&#039;t mind launching one external process to do the test and you want portability to non-bash shells, use find:if test -n &quot;$(find /tmp -maxdepth 1 -name &#039;*.cache&#039; -print -quit)&quot;
then
&#160;&#160;&#160;&#160;echo Cache files exist
else
&#160;&#160;&#160;&#160;echo No cache files
fi</description> <content:encoded><![CDATA[<p>WAYYYYYY too complicated, all of you.</p><p>If what you want is reasonably terse script that works entirely with bash builtins and doesn&#8217;t fail unless bash can&#8217;t expand the glob without blowing out its command line buffer, use nullglob in a subshell:</p><p>if test -n &#8220;$(shopt -s nullglob; cd /tmp; echo *.cache)&#8221;<br
/> then<br
/> &nbsp;&nbsp;&nbsp;&nbsp;echo Cache files exist<br
/> else<br
/> &nbsp;&nbsp;&nbsp;&nbsp;echo No cache files<br
/> fi</p><p>If you&#8217;d rather know that your script will always do the right thing, you don&#8217;t mind launching one external process to do the test and you want portability to non-bash shells, use find:</p><p>if test -n &#8220;$(find /tmp -maxdepth 1 -name &#8216;*.cache&#8217; -print -quit)&#8221;<br
/> then<br
/> &nbsp;&nbsp;&nbsp;&nbsp;echo Cache files exist<br
/> else<br
/> &nbsp;&nbsp;&nbsp;&nbsp;echo No cache files<br
/> fi</p> ]]></content:encoded> </item> <item><title>By: Dmitry</title><link>http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/comment-page-1/#comment-193532</link> <dc:creator>Dmitry</dc:creator> <pubDate>Wed, 21 Sep 2011 14:19:15 +0000</pubDate> <guid
isPermaLink="false">http://www.ducea.com/?p=672#comment-193532</guid> <description>if ls /tmp &#124;  grep  -sq *.cache
then
echo &quot;Cache files exist: do something with them&quot;
else
echo &quot;No cache files...&quot;
fi</description> <content:encoded><![CDATA[<p>if ls /tmp |  grep  -sq *.cache<br
/> then<br
/> echo &#8220;Cache files exist: do something with them&#8221;<br
/> else<br
/> echo &#8220;No cache files&#8230;&#8221;<br
/> fi</p> ]]></content:encoded> </item> <item><title>By: Dmitry</title><link>http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/comment-page-1/#comment-193531</link> <dc:creator>Dmitry</dc:creator> <pubDate>Wed, 21 Sep 2011 13:59:08 +0000</pubDate> <guid
isPermaLink="false">http://www.ducea.com/?p=672#comment-193531</guid> <description>files=$(find /tmp -type f -name &quot;*.cache&quot; &#124; wc -l)if [ &quot;$files&quot; != &quot;0&quot; ]
then
echo &quot;Cache files exist: do something with them&quot;
else
echo &quot;No cache files...&quot;
fi</description> <content:encoded><![CDATA[<p>files=$(find /tmp -type f -name &#8220;*.cache&#8221; | wc -l)</p><p>if [ "$files" != "0" ]<br
/> then<br
/> echo &#8220;Cache files exist: do something with them&#8221;<br
/> else<br
/> echo &#8220;No cache files&#8230;&#8221;<br
/> fi</p> ]]></content:encoded> </item> <item><title>By: jman</title><link>http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/comment-page-1/#comment-193335</link> <dc:creator>jman</dc:creator> <pubDate>Tue, 23 Aug 2011 06:02:41 +0000</pubDate> <guid
isPermaLink="false">http://www.ducea.com/?p=672#comment-193335</guid> <description>My little bash script for confirming that a file exists for a non linux user:clear
echo &quot;Enter a file to see if it exists:&quot;
read file
echo &quot;searching system......&quot;
sleep 1
locate $file &gt; file.finder
if [ $file != &quot;1&quot; ];then
echo &quot;$file EXISTS, IN THESE PLACES:&quot;
cat file.finder
sleep 4
rm file.finder
else
echo &quot;$file doesn&#039;t exist!&quot;
fi</description> <content:encoded><![CDATA[<p>My little bash script for confirming that a file exists for a non linux user:</p><p>clear<br
/> echo &#8220;Enter a file to see if it exists:&#8221;<br
/> read file<br
/> echo &#8220;searching system&#8230;&#8230;&#8221;<br
/> sleep 1<br
/> locate $file &gt; file.finder<br
/> if [ $file != "1" ];then<br
/> echo &#8220;$file EXISTS, IN THESE PLACES:&#8221;<br
/> cat file.finder<br
/> sleep 4<br
/> rm file.finder<br
/> else<br
/> echo &#8220;$file doesn&#8217;t exist!&#8221;<br
/> fi</p> ]]></content:encoded> </item> <item><title>By: funny</title><link>http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/comment-page-1/#comment-192986</link> <dc:creator>funny</dc:creator> <pubDate>Wed, 15 Jun 2011 16:17:42 +0000</pubDate> <guid
isPermaLink="false">http://www.ducea.com/?p=672#comment-192986</guid> <description>#!/bin/bashset -xj=0cd /Path/of/the/fileToday=`date &#039;+%b %e&#039;`ls -lrt a*access*&#124; grep &quot;$Today&quot; &#124;awk -F&quot; &quot; &#039;{print $9}&#039; &gt; tempfor i in `cat temp`;dogrep &quot;500&quot; $i  &#124;awk -F&quot; &quot; &#039;{print $9}&#039; &gt; fivehund_errorfileFile_time=`ls -lrt fivehund_errorfile &#124; awk -F&quot; &quot; &#039;{print $6 &quot; &quot; $7 &quot; &quot; $8}&#039;`Time_now=`date &#039;+%b %e %H:%M&#039;`#if [ &quot;$File_time&quot; == &quot;$Time_now&quot; ];#if [ &quot;$File_time&quot; == &quot;$Time_now&quot; -a test -s fivehund_errorfile ];
#if [ $File_time == $Time_now ] -a [ test -s fivehund_errorfile ];
#if [ $File_time == $Time_now -a test -s fivehund_errorfile ];
#if [ [$File_time == $Time_now] -a [test -s fivehund_errorfile] ];
if [ $File_time == $Time_now ] &amp;&amp; [ test -s fivehund_errorfile ];
thenj=1echo &quot;500 found in $i file&quot;elseecho &quot;not found in $i file&quot;fi
donegetting the messg as
++ &#039;[&#039; Jun 15 16:54 == Jun 15 16:54 &#039;]&#039;
./five_check.sh: [: too many argumentscan some one help me to fix this error/warning</description> <content:encoded><![CDATA[<p>#!/bin/bash</p><p>set -x</p><p>j=0</p><p>cd /Path/of/the/file</p><p>Today=`date &#8216;+%b %e&#8217;`</p><p>ls -lrt a*access*| grep &#8220;$Today&#8221; |awk -F&#8221; &#8221; &#8216;{print $9}&#8217; &gt; temp</p><p>for i in `cat temp`;do</p><p>grep &#8220;500&#8243; $i  |awk -F&#8221; &#8221; &#8216;{print $9}&#8217; &gt; fivehund_errorfile</p><p>File_time=`ls -lrt fivehund_errorfile | awk -F&#8221; &#8221; &#8216;{print $6 &#8221; &#8221; $7 &#8221; &#8221; $8}&#8217;`</p><p>Time_now=`date &#8216;+%b %e %H:%M&#8217;`</p><p>#if [ "$File_time" == "$Time_now" ];</p><p>#if [ "$File_time" == "$Time_now" -a test -s fivehund_errorfile ];<br
/> #if [ $File_time == $Time_now ] -a [ test -s fivehund_errorfile ];<br
/> #if [ $File_time == $Time_now -a test -s fivehund_errorfile ];<br
/> #if [ [$File_time == $Time_now] -a [test -s fivehund_errorfile] ];<br
/> if [ $File_time == $Time_now ] &amp;&amp; [ test -s fivehund_errorfile ];<br
/> then</p><p>j=1</p><p>echo &#8220;500 found in $i file&#8221;</p><p>else</p><p>echo &#8220;not found in $i file&#8221;</p><p>fi<br
/> done</p><p>getting the messg as<br
/> ++ &#8216;[' Jun 15 16:54 == Jun 15 16:54 ']&#8216;<br
/> ./five_check.sh: [: too many arguments</p><p>can some one help me to fix this error/warning</p> ]]></content:encoded> </item> <item><title>By: Trevor Sturdevant</title><link>http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/comment-page-1/#comment-192939</link> <dc:creator>Trevor Sturdevant</dc:creator> <pubDate>Wed, 18 May 2011 20:25:16 +0000</pubDate> <guid
isPermaLink="false">http://www.ducea.com/?p=672#comment-192939</guid> <description>I found all of the above to be too inefficient.. Try this instead.for i in filename*; do FOUND=$i;break;done
if [ $FOUND == &#039;filename*&#039; ]; then
echo “No files found matching wildcard.”
else
echo “Files found matching wildcard.”
fi</description> <content:encoded><![CDATA[<p>I found all of the above to be too inefficient.. Try this instead.</p><p>for i in filename*; do FOUND=$i;break;done<br
/> if [ $FOUND == 'filename*' ]; then<br
/> echo “No files found matching wildcard.”<br
/> else<br
/> echo “Files found matching wildcard.”<br
/> fi</p> ]]></content:encoded> </item> <item><title>By: Delicious Bookmarks for February 17th through February 18th &#171; Lâmôlabs</title><link>http://www.ducea.com/2009/03/05/bash-tips-if-e-wildcard-file-check-too-many-arguments/comment-page-1/#comment-192315</link> <dc:creator>Delicious Bookmarks for February 17th through February 18th &#171; Lâmôlabs</dc:creator> <pubDate>Fri, 18 Feb 2011 07:04:29 +0000</pubDate> <guid
isPermaLink="false">http://www.ducea.com/?p=672#comment-192315</guid> <description>[...] Bash tips: if -e wildcard file check =&gt; [: too many arguments &#124; MDLog:/sysadmin &#8211; February 17th  ( tags: bash linux howto programming reference shell unix tips ) [...]</description> <content:encoded><![CDATA[<p>[...] Bash tips: if -e wildcard file check =&gt; [: too many arguments | MDLog:/sysadmin &#8211; February 17th  ( tags: bash linux howto programming reference shell unix tips ) [...]</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Served from: www.ducea.com @ 2012-02-08 19:41:40 by W3 Total Cache -->
