I created a shell script called blossom() because my girlfriend's dog Blossom poops and pees on the floor all the time.

blossom() {
   echo poops and pees on floor all the time

Because I am such a curious kid, I want to search where this shell is stored and found on some forum that it is within declare -f. So I want to find it in the output but also read around it again.

I had some ideas and tried

declare -f | grep blossom

well, that only showed the top line which was blossom() {

So I thought, hm... let's try

declare -f | less

but that is still too much to search through...

what about

declare -f > test_file
nano test_file

well this one does solve some of what I am trying to do and I can use ^W for "Where at" and find it no problem. But this creates a file and I do not want to do that.

How can I, with a certain set of commands, pre-search an output with scroll up and down capability. Maybe using less command and have that pre-searched. Is this possible?

  • Why not declare -f blossom – xae Mar 10 '15 at 20:48

Try the following to start less with blossom already searched for:

declare -f | less -p blossom

From the documentation of less:

-ppattern or --pattern=pattern
    The -p option on the command line is  equivalent  to  specifying
    +/pattern;  that  is, it tells less to start at the first occur‐
    rence of pattern in the file.

If your question was less general than that, and you want just the source for function blossom, use the following:

declare -f blossom
  • Sometimes Ill read documentation and scan over that very thing, and just not know what it means. Thank you! I kinda feel silly, since I scanned the docs already and missed this! It seems that both of your answers were incredibly helpful! Thanks! – Michael Bruce Mar 10 '15 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.