Try this... #!/bin/bash shopt -s nullglob # no need for ls, echo is built-in to the shell var=$( echo *.txt ) if [ -n "$var" ]; then echo "yes" else echo "no" fi
On Fri, Mar 04, 2011 at 12:35:06AM +0100, William Windels wrote: > Hello, > > Can someone help me with a litle bash-script? > > I would like to test if there is a txt-file in the current working directory. > > I was thinking about the following code for the bashscript: > > var=${ls *.txt} && if [ -n "$var" ]; then echo "yes" else echo "no" ; fi > > The error I have here is: > ${ls *.txt}: bad substitution > > the -n options looks if the variable is not empty , I think. > > Could someone help me pls? > > Thx for your help, > > best regards, > William Windels > > -- > You received this message because you are subscribed to the Google Groups > "MacVisionaries" group. > To post to this group, send email to macvisionaries@googlegroups.com. > To unsubscribe from this group, send email to > macvisionaries+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/macvisionaries?hl=en. > -- You received this message because you are subscribed to the Google Groups "MacVisionaries" group. To post to this group, send email to macvisionaries@googlegroups.com. To unsubscribe from this group, send email to macvisionaries+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/macvisionaries?hl=en.