If you type this in to the bash command prompt (not loaded into bashrc)

function_name () { ls -1 ; ls -ltr ; } 

When function_name is typed in at the command prompt the shell will commit ls -1 and then ls -ltr Where does the shell store this function, because once the shell is terminated, function_name is lost to the next session.

  • Yes, when a process terminates it terminates. It is no more. Everything that was in its memory is gone. That being said, by default just before terminating bash writes a history file, ~/.bash_history, and you may interactively retrieve the function definition from history. – AlexP Nov 25 '16 at 13:05
  • Maybe you are asking where to put the function so that it will be permanently available? In that case, put it in your .bashrc. – Michael Vehrs Nov 25 '16 at 13:11
  • where does the shell store that function during that particular session - in mememory ? In RAM? if the function was was in the bashrc, the shell would read in the function and store it somewhere. It would in effect die the same as if it wastyped in, but it would be reloaded by the bashrc. next time. The memory location would be the same whether the function was read in from bashrc or typed in at command line. What is the shell's storage area for alias's or functions or if you type in a variable at command line like thisvar="astring" then echo $thisvar. where was the string stored? – capser Nov 25 '16 at 13:49

Your Answer

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

Browse other questions tagged or ask your own question.