Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running an executable in Mac Terminal

Tags:

terminal

macos

I just made a .c file and compiled it with gcc in the terminal on OS X 10.8.2.

My syntax was gcc -o <filename> <sourcefile> and that was fine. Now I see I have an executable and file <filename> tells me as such, but I'm not sure how to actually run it beside double clicking the icon, /lame. When I try running the executable by just typing I get command not found, but I thought it was executable...?

Thank you.

EDIT: I"m so stupid, it was just open <filename>

like image 453
EdgarArout Avatar asked Feb 26 '13 03:02

EdgarArout


People also ask

How do I open a UNIX executable file on a Mac?

I figured out that you can open them by opening TextEdit, then from the File dropdown menu select Open. Select the Unix executable file and it will open.


1 Answers

Unix will only run commands if they are available on the system path, as you can view by the $PATH variable

echo $PATH 

Executables located in directories that are not on the path cannot be run unless you specify their full location. So in your case, assuming the executable is in the current directory you are working with, then you can execute it as such

./my-exec 

Where my-exec is the name of your program.

like image 134
Perception Avatar answered Sep 19 '22 14:09

Perception