env displays a list of all environment variables

$ env |wc -l

Total environment variables = 63

According to help export

-p   display a list of all exported variables and functions

$export -p |wc -l 

Environment variables+lines of functions=63 then lines of functions=0

set disply a list of environment variables+ shell variables+functions

$set |wc -l

Then for showing only variables(environment variables+shell variables)

$(set -o posix ;set)|wc -l

It means lines of functions= 4772-172 not zero please explain to me what's happening?

  • 1
    Each function spans multiple lines, counting number of lines is plain wrong. Also i don't understand what is tripping you up here if you know the difference between environment variable and shell variable. – heemayl Oct 17 '16 at 13:10
  • I want to know why the result of export -p and env are the same! it means ,we have no functions? – Sinoosh Oct 17 '16 at 13:14

The confusion arises from the fact that export -p by default only shows exported variables (declare -x), not functions.

To display the exported functions (declare -fx) using export:

export -fp

Also just to clarify, counting number of lines to get number of functions is completely wrong as function definitions span multiple lines (even if it defined in a single line while declaring, set shows them in multiple lines).

|improve this answer|||||
  • thanks,why in ´help export´ write like that? – Sinoosh Oct 17 '16 at 16:27
  • 1
    @Sinoosh Hmmmm, i wonder too. I will dig deeper when i get a chance. – heemayl Oct 18 '16 at 6:04

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.