The Wayback Machine - https://web.archive.org/web/20240308071951/https://www.geeksforgeeks.org/declare-command-in-linux-with-examples/
Open In App
Related Articles

declare command in Linux with Examples

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
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:

Last Updated : 15 May, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials