Open In App

declare command in Linux with Examples

Last Updated : 15 May, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Syntax:

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:

Options:

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

    Example:

  • -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:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads