Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello,
I have the latest version of Ubuntu installed and now I am trying to learn how it works.
Problem: I cant get a program that I wrote to run.
I wrote the classic "Hello world" and compiled it in the terminal with the following statement: gcc -o hello hello.c (there were no complaints from the system)
I checked via ls -l for a proper output file and found hello and it has the proper permissions for execution. when I try to run it from the command prompt $ hello it doesnt run and I get the following
The program 'hello' can be found in the following packages:
* hello-dbs
* hello
* hello-debhelper
Try: sudo apt-get install <selected package>
bash: hello: command not found
In suggestions?
Thanks in advance, rlh
Last edited by sleepyjake; 09-02-2007 at 10:44 AM.
You need to use "./hello" to tell the shell to execute the file in the current directory. Otherwise, the shell will search for directories listed in $PATH for "hello" and since it's not in any of those directories, you'll get the "command not found" message.
Ok.
So even though I have navigated via the terminal to the directory where I have stored the source and compiled and linked the file. I need to tell the shell where I am via ./ ?
Yes, because the shell looks for executables in the directories listed in your $PATH environment variable (you can see which directories are in there with "echo $PATH").
You should read the pages in linuxcommand.org - they're really helpful and surely clear some things (like this, for example). There are some "shortcuts" in Linux shells, or ways to express something shorter than it actually is, and the dot is one of them (it's a file that always refers to the directory where it is in) - two dots (..) is another file found in every other directory than root directory, and it refers to the upper/parent directory (the dir where the directory is in, that has the two dots file in..got it?)
Like said above, when you issue a command, your shell tries to find the executable for you. There are several ways to execute an executable, for example:
- by giving a full path to it, and the executable name, like /bin/bash
- by giving just the executable name, for example just bash
In the latter case the shell doesn't automagically know where 'bash' (or anything) is, but it searches certain places where it can be. Usually (but can be configured otherwise if I'm right) it first checks all the directories mentioned in $PATH environmental variable (order matters - the executable is executed from where it's first found). If it's found somewhere in there, it's executed there; if not, then the shell usually checks to see if the file is in the current working directory. So if you have executables that have exactly the same name (but in different places), your shell runs the one that is found first. To make sure you run the right one, you can provide the full path to the executable, telling your shell to launch just that executable. And because you don't want to type in your full current-working-directory-here name, you use a special file (the dot, '.') as a "shortcut" to the directory: there ./ means just the same as if you had typed the full current working directory path.
Ubuntu has this nice feature not in every distribution that if you type in a command name that is not found (from $PATH; I'm not sure if it's even checked against the parent working directory, as your example seems to show..), Ubuntu checks to see if there's a program of that name in some package that's available in it's reposity. If yes, it kindly tells you the package name you need to install to obtain the executable you tried to run..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.