0

I am writing an SVN script that will export only changed files. In doing so I only want to export the files if they don't contain a specific file.

So, to start out I am modifying the script found here.

I found a way to check if a string contains using the functionality found here.

Now, when I try to run the following:

filename=`echo "$line" |sed "s|$repository||g"`
if [ ! -d $target_directory$filename ] && [[!"$filename" =~ *myfile* ]] ; then

fi

However I keep getting errors stating:

/home/home/myfile: "no such file or directory"

It appears that BASH is treating $filename as a literal. How do I get it so that it reads it as a string and not a path?

Thanks for your help!

Community
  • 1
  • 1
thiesdiggity
  • 1,897
  • 2
  • 18
  • 27
  • Where is the error occurring? What are the contents of the variables? Have you tried running your script with `bash -x`? – Adam Liss Jan 23 '13 at 00:03

1 Answers1

1

You have some syntax issues (a shell script linter can weed those out):

  • You need a space after "[[", otherwise it'll be interpretted as a command (giving an error similar to what you posted).
  • You need a space after the "!", otherwise it'll be considered part of the operand.

You also need something in the then clause, but since you managed to run it, I'll assume you just left it out.

  • You combined two difference answers from the substring thing you posted, [[ $foo == *bar* ]] and [[ $foo =~ .*bar.* ]]. The first uses a glob, the second uses a regex. Just use [[ ! $filename == *myfile* ]]
that other guy
  • 116,971
  • 11
  • 170
  • 194
  • Thanks for the tip! I actually had to use "[[ $filename != \*myfile\* ]]". For some reason the !$filename.... wasn't evaluating correctly (always returning false). – thiesdiggity Jan 23 '13 at 02:59
  • OK, scratch that last comment. I didn't have a "space" after the !, both work as intended. – thiesdiggity Jan 23 '13 at 03:02