declare command in Linux with Examples

The declare is a builtin command of the bash shell. It is used to declare shell variables and functions, set their attributes and display their values.


declare [-a] [-f] [-g] [-F] [-x] [-p] [name[=value]] [name[=value]] …

Example: In this example we will declare a variable using declare command.

The output of the above typed commands is as follow:


  • -p This is used to displays the options and attributes of each variable name if it is used with name arguments.


  • -f : Each name is treated as the name of function, not variable. So you can say this option restrict action or display to function names and definitions.
  • -F : When showing information regarding a function, it show only the function’s name and attributes. So the contents of the function will not be displayed.
  • -g : It causes all operations on variables to take effect in global scope.

Note: For more details, you can use –help option with “declare” command as follows:

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.