0

I am taking a linux class this semester and one of the questions on a lab is:

Use the set command to find out all directories in your path.

Normally, I would just use $PATH to find out the directories in my path. But, obviously the question is asking us to use set. I have never used set before and went to do man set to find out a little bit about the command, but, to my surprise my shell (bash) didn't have an entry for set. However, I see that there is a set man page here http://linuxcommand.org/lc3_man_pages/seth.html So that is my first question: Why isn't there an entry when I use the command man set?

I posted on a discussion board that if i just type set it spits out a bunch of function stuff that looks like info from rails which I have installed on my machine. No idea whats going on there.. My professor explained that set is a "built in" function which is why it might not have documentation in the man pages.

After looking at the set documentation online a little bit, I still have no idea how I can get it to spit out my $PATH and after doing a little research I haven't found anything that really explains set well in the context that I need to use it

To be clear I am not simply seeking an answer here, a general explanation pointing me in the right direction would be very helpful.

TL;DR

  1. Why can I find a man entry online for set but when I use the command man set no documentation is available in my terminal.

  2. What might be a general way to use set to find the directories in my PATH

Thanks!

edit: The full question:

  1. Use the set command to find out all of the directories in your “PATH.” You will get a lot of data and you will need to pipe to another command to filter out just what you want. Please note that PATH is capitalized. Paste or type those directories below. You will get a bunch of data so see if you can dig through it to get the answer.

2 Answers 2

2

You are correct that set is a shell builtin: that means that its documentation is in the manual page for bash (in the SHELL BUILTIN COMMANDS section) rather than in a manpage of its own. More simply, you can get basic usage information by typing

help set

from the shell prompt. As to using it to "find out all directories in your path" it would be useful to have some context - I can't really imagine what your instructor/teacher might be intending, aside from perhaps using set -- $PATH (with a suitable IFS field separator) to assign path elements to the shell's positional parameters, and then print them.

1
  • Thanks! I didn't know about help set I have edited my question to include the full question from the assignment to provide context as you requested. Jan 30, 2015 at 3:41
1
  1. There is a manual entry for set: the one derived from the POSIX standard's specification of set. To view it, you must have manpages-posix-dev installed (well, manpages-posix would do, but you might as well install both). Then you can do:

    man 1posix set
    

    Or visit the online Ubuntu manpage: http://manpages.ubuntu.com/set.1posix
    When possible, do prefer the manpages from that site, since it reflects the manpages that can be made available on your Ubuntu system. Other sites may vary markedly.

  2. What your prof probably intended was that you would use the grep command in combination with set. This is not the Right Way™ for a few reasons. grep can be used to filter out lines from the output of another command, or from a file. And set's default output is ... every variable set in your shell and their values, including PATH.

Lastly, you forgot to click Next while viewing the Bash documentation.

6
  • Thank you very much, I will look into this info. This is always a comforting first sentence "This builtin is so complicated that it deserves its own section." :) Jan 30, 2015 at 3:57
  • @MichaelJames you're welcome. But I should tell you that set's default behaviour is to print a list of every variable set in your shell, including PATH. Since there are so many, PATH gets lost in the output. So the manpage may not be as useful here.
    – muru
    Jan 30, 2015 at 4:02
  • Eureka! So that is what is happening when I just say set I have a whole bunch of environment variables. Now, how to go about piping the information from path... Jan 30, 2015 at 4:13
  • @MichaelJames what are the odds of you saying "piping"?
    – muru
    Jan 30, 2015 at 4:23
  • hahaha no I must admit I do know what piping is.. just not sure what to do in this particular case. We aren't supposed to use regex yet..Learning about grep now. I think that's my ticket. Jan 30, 2015 at 4:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .