I have no problem running my C programs by switching to their directory and starting them with ./
. However, I'm not sure why changing to the directory and then typing sh [Program Name]
gives me this error:
Fortune_Teller_5000: 1: Fortune_Teller_5000: Syntax error: "(" unexpected
and:
./Fortune_Teller_5000: 1: ./Fortune_Teller_5000: Syntax error: "(" unexpected
I read in the bash man pages that the sh
command is a shell that doesn't read the .bashrc
file, so I'm a little confused as the why I can't use it to run programs I made. I did use it to install my printer drivers according to the directions on the HP Linux Imaging and Printing page.
Typing
sh program_name
assumes that program_name is a shell script and executes the script (so it must be in a sh/bash language). IfFortune_Teller_5000
is a binary file (a Compiled C program, or even C source code), runningsh Fortune_Teller_5000
will not work as expected.Here are 2 ways you could do it:
sh
then ENTER, and then type./Fortune_Teller_5000
(you may need tocd
into the proper directory)sh -c ./Fortune_Teller_5000
orsh -c /path/to/folder/Fortune_Teller_5000
Running
sh [Program Name]
instructs thesh
program to execute a shell script named[Program Name]
so if this file is a C program, the command will fail.The POSX specification for sh, the standard command language interpreter states that the argument for
sh
should be the “pathname of a file containing commands”.