Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Possibly a dumb answer but in my terminal I would have to type in:</p> <pre><code>./factorial.awk </code></pre> <p>where the file is factorial.awk.</p> <p>You could edit your path environment variable to include . but ./ should work just fine I think. And adding . to $PATH could prove to be very dangerous in some situations where you would run code that you did not expect to.</p> <p>Does that work??</p> <p>EDIT:</p> <p>./factorial.awk -bash: ./factorial.awk: /usr/bin/gawk: bad interpreter: No such file or directory</p> <p>That says that it ran the file but could not find the program gawk. Please type in 'which gawk' and then 'which awk'.</p> <p>Is your first line supposed to be:</p> <pre><code>#!/usr/bin/awk </code></pre> <p>Also, just to amuse me, type in:</p> <pre><code>sudo apt-get install gawk </code></pre> <p>That will make sure you actually have gawk on your system.</p> <p>EDIT2: I took a look at your code and this is what I have now. I removed two quotes and a dash.</p> <pre><code>#!/usr/bin/gawk # I think we do not need these (p.179) so I comment them out, since I do not know where else to put them. # The same bug occurs also with them. #fact = number #for (x = number -1 ; x &gt; 1; x--) # fact *= x awk # factorial: returns factorial of user-supplied number BEGIN { printf("Enter number: ") } $1 ~ /^[0-9]+$/ { # assign value of $1 to number &amp; fact number = $1 if (number == 0) fact = 1 else fact = number #loop to multiply fact*x until x = 1 for (x = number - 1; x &gt; 1; x--) fact *= x printf("The factorial of %d is %g\n", number, fact) #exit -- saves user from typing ^-d exit } # if not a number, prompt again. { printf("\nInvalid entry. Enter a number: ") } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload