Basic 'print' & 'puts' Mac OS terminal commands not found

I followed this article to install & update ruby with a package manager but I clearly messed up somewhere.

https://stackify.com/install-ruby-on-your-mac-everything-you-need-to-get-going/

If I try to 'puts' or 'print' anything I get -bash: print: command not found / -bash: puts: command not found returned.

'ls' & 'cd' commands still work for example, but echo $path returns nothing.

As you have probably guessed, I am completely new to code & stupidly copy pasted lines into the shell that I don't understand.

Is this a path issue?


Solution 1:

  • print is not a standard bash command. I think so because man print returns no manual entry.

  • puts is a Standard C Library function and should be used inside a file and used as:

    #include <stdio.h>
    puts(const char *s);
    

    The function puts() writes the string s, and a terminating newline character, to the stream stdout.

    An example:

/* puts example : hello world! */
#include <stdio.h>

int main ()
{
  char string [] = "Hello world!";
  puts (string);
}

http://www.cplusplus.com/reference/cstdio/puts/

  • echo $path returns an empty line. It is case-sensitive. Use echo $PATH.

  • You need to save the ruby script in a file with appropriate file extension: .rb. Open Terminal, go the directory where the file is located using cd path/to/directory and run ruby filename.rb to see the results.