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.
i have to write a shell script that takes name of the file as command line argument and the script should use path envt variable to look for the specified file and specify where are the different instance of the filename specified exist
firstly enter the filename
echo "enter the filename"
read filename
by using ls command we can get to know how many links are there for that file
but i don't know how to get the pathname of the file and its links
after knowing the pathnames of the file i can set the path variable using export command
can any one tell me how to get the pathname of the file i entered as a command line argument
LQ users are not very eager to do your homework for you. You should put in some work of your own, post what you already have and specify where it's failing. Remember that your teacher might be a member here too. That being said, look into the commands dirname and basename and what they do. Some reading: Bash Guide for Beginners Advanced Bash-Scripting Guide
If it's not your homework then I apologize sincerely. The structure of your post made me think it was. As pointed out by grail, show us what you have and where you encounter problems or errors and we'll be glad to help you out.
For the benefit of EricTRA, all of this poster's posts look like homework; if you made a mistake in assuming that this post is homework, it is a mistake that I would have made, too. Maybe, if the OP were to explain in which non-homework context this question could arise, that would help.
Additionally, the poster has been asked before to show what he has done so far and explain where he is stuck, and that hasn't yet happened.
The original statement is also confusing:
Quote:
i have to write a shell script that takes name of the file as command line argument
that part seems clear
Quote:
and the script should use path envt variable to look for the specified file
So, you are only interested in instances that are files and that have exactly the filename specified as a parameter on the invocation of your script. You are not interested in directories or links and you are not interested in files of that name that may exist anywhere else in the filesystem and behaviour is undefined when you find zero files which have this filename. Is this correct?
Quote:
by using ls command we can get to know how many links are there for that file
but i don't know how to get the pathname of the file and its links
Now links have crept in and I'm not sure that I have understood what you mean. Do you expect there to be links of the same name as the file, or do you mean that there could be links pointing to the named file? You could mean either, but neither seem to relate to the problem stated in the first part of the question. And both seem a bit odd when considered in the light of plausible interpretations of the last part, which doesn't seem, superficially, to be about links.
Quote:
after knowing the pathnames of the file i can set the path variable using export command
So, after having found a file (or a filesystem object) that you know is in the path, you are going to set the path so that it includes the file that you have just found. This seems to have no purpose unless you are deleting something from the path, as you know that the file is already in the path.
this was not my homework but was a question in previous year exam of my college of linux and i wanted to solve it thats it and the question was
write a shell script that takes as a command line parameter the name of a file.The script should use the PATH envt variable to look for the specified file and specify where are the different instance of the filename specified exist....
its ok with me i will not post anything from now on if this is not allowed
Well you can probably understand our skepticism then if it sounds exactly like homework then (seeing as exams are just the next evolution of homework).
The fact still remains that you have not shown any interest in showing us what you have so far and just like homework, no one here is willing to do all the work for you.
So again I will ask (which by the way you never replied to), what have you done so far and where are you stuck?
If you went to a college to study linux then this seems like a fairly trivial question.
whereis is for special files. I thought first `which`. But ithe OP could be really need where-all-in-the-path does the exe occurs?
Quote:
and the script should use path envt variable to look for the specified file and specify where are the different instance of the filename specified exist
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.