0

I am getting binary operator expected error while running my script. the script basically checks if a file exists in by checking the partial file name is present in the dir and then calls a function.

if [ -e $file_name* ] ; then 
 func_call
else 
 echo "file not found" 
 exit
fi

what am I doing wrong ??

Nadia Alice
  • 111
  • 5
  • The `-e` test doesn't support wildcards. There are ways to check for matching files, but they're rather messy; see ["Test whether a glob has any matches in Bash"](https://stackoverflow.com/questions/2937407/test-whether-a-glob-has-any-matches-in-bash). – Gordon Davisson Jul 19 '22 at 06:52
  • Since you are using `[`, filename expansion occurs on its arguments. You get after `-e` in general a list of files (those matching the glob), but `-e` expects a single argument. That's why you get the error message. However it is unclear to e why you want to test the existence anyway: If your glob pattern expands, you already **do** know that the files matchng the pattern exisit.. – user1934428 Jul 19 '22 at 08:33
  • @user1934428 could u please help , what should I do in this case? I need to check if the argument passed while running the script matches with the file present in the dir. for ex **./test.sh abc, so abc is stored in the $file_name variable and hence the check for abc_123.txt in the dir** – Nadia Alice Jul 19 '22 at 08:42
  • Since your question is already closed, I suggest that you ask a new question, in which you describe what kind of arguments your script wants to get (this information is completely absent from your present question, and your current script does not use any argument at all), and describe what effect you want to see, and for comparision describe what you see instead with your present script. Make sure that you specify input and and output of your script as precisely as possible. – user1934428 Jul 19 '22 at 08:52
  • I've posted a new question on the same issue , kindly look into it – Nadia Alice Jul 19 '22 at 12:05

0 Answers0