2

I have a c file that checks whether there is a ! in the argument given (ie ./a.out hi!) and return 0 if it does and 1 if it doesn't, which works as it's supposed to.

I need to make a bash shell file (.sh) that uses the c file to check if files in a directory contain the character, ie. if the directory has dogs!.sh fly!.c ring.txt, executing ./script.sh should return

dogs!.sh
fly!.c

But I have no idea how to do so? Can anybody help out?

1
  • I think you left an extraneous } in your c file, right by the else statement. Your if block doesn't use a bracket, so when it reaches that next one it thinks you're ending the main() routine. Commented Apr 29, 2020 at 23:00

1 Answer 1

3

Your compile line:

gcc includes.c

Will produce an output program called a.out. You need to run that command, not try to execute your C source as a shell script, which is what your current script is doing. Example:

ret=$(./a.out ${file})

You don't need the ret, though, since your program has no output. Just check the exit value.

if [[ $? -eq 0 ]]

Editorial note: this answer assumes that you've copy/pasted something wrong when asking this question, since your error message shows alpha.c, but that's not mentioned anywhere else. And that you fix the syntax errors in your C program, too!

Sign up to request clarification or add additional context in comments.

1 Comment

You can also check the return value directly if a.out "$file"...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.