1

I'm a student and this is my first exposure to bash scripting, besides messing with a simple Makefile for c.

#!/usr/bin/sh
gcc -g -std=c99 -Wall -c field.c 
gcc -g -std=c99 -Wall -c testField.c 
gcc -g field.o testField.o -o testField 
#testField get 0xa 0 1 > PA1output.txt 
#testField get 0xaa 0 3 >> PA1output.txt

is my script.I want to compile field.c and testField.c into the executable testField. No matter if I leave the last 2 lines commented out or not, they linux terminal hangs and after 10 seconds of nothing happening I press ctrl+c to stop it. Ultimately I want to redirect output to PA1output.txt, then concatenate things on the end of the file, but I want to rewrite the file contents each time.

As far as I understand it, > rewrites the contents of the specified file, and >> concatenates onto the end.

This is not my homework, I want to automate testing of other homework I have. 'testField get 0xaa 0 3 are arguments into my c program.'

I tried Bash script hangs but that didn't answer my question totally.

My script is called 'as' to make it easy to type.

Why does the terminal hang and how do I get the script to do what I described above?

Thanks.

Community
  • 1
  • 1
Clara
  • 281
  • 1
  • 3
  • 13
  • 1
    Probably depends on what `testField` does. If it's, for example, waiting for user input, it will hang forever... – Rob I Sep 11 '12 at 00:46

2 Answers2

5

Your system has another program called ‘as’ which is an assembler. You are likely running this rather than your script, and it hangs because the assembler is waiting for input from your terminal.

If you insist on keeping the name, you should run your script with a full or partial pathname (like ‘./as’) so that the correct program is run.

You will probably find that your script will not run without the ‘#’ at the beginning of your first line. However, another way to run your script is ‘sh ./as’ from the command line, which does not depend on having the #! line.

Jeremy
  • 66
  • 1
1

As Jeremy described, it's most likely a conflict of names.

If you are running your script from the command line (I really hope you are), you don't have to be afraid of giving your scripts (and all file names for that matter) longer, but more specific, names. Most (if not all) command line interfaces on linux have some form of tab-expansion. All you have to do is type enough of the name to make it unique, then press [Tab], and the shell should complete the name for you.

Here's a more thorough explanation for Bash.

Andrew W Carson
  • 163
  • 1
  • 7
  • Although I like your answer, and the provided link was useful, I checked @Jeremy because that user explained why my script was not working. – Clara Sep 16 '12 at 01:48