I am trying to run one of the example from Beej's Guide to Network Programming (https://beej.us/guide/bgnet/), specifically showip.c (The link to the program is here: https://beej.us/guide/bgnet/examples/showip.c). Using gcc, I've typed in
gcc -o showip showip.c
Then ran the program
showip www.example.net
and I get an error showip: command not found on the same directory where the code and the program is compiled at. I'm not sure why this is the case. I've even cloned the code from his GitHub and used makefile to compile the program and yet I'm getting the same error. What exactly am I doing it wrong here?
CodePudding user response:
This is actually problem with how you're running the program.
On Linux systems (unlike Windows systems) an executable in the current directory is not by default searched by the shell for programs to run. If the given program does not contain a path element (i.e. there are no /
characters in the name) then only the directories listed in the PATH
environment variable are searched.
Since the current directory is not part of your PATH, prefix the command with the directory:
./showip www.example.net
CodePudding user response:
Since the program showip
is not in your $PATH
you have to tell
your shell that it's in the current directory:
./showip
Or add the current directory to your $PATH
but it's a less secure
option:
PATH=:$PATH
or
PATH=.:$PATH
and run it as you're trying now:
showip
CodePudding user response:
Is the working directory on your path? Likely not.
Try ./showip