Linux Commands: Declare variables and give them attributes
declare-Linux Command
declare command- Declare variables and give them attributes
Syntax: declare [-afFrxi] [-p] [name[=value]]
Description: The declare command can be helpful in identifying variables, environmental or otherwise. This can be especially useful with arrays.
-r readonly
(declare -r var1 works the same as readonly var1)
This is the rough equivalent of the C const type qualifier. An attempt to change the value of a readonly variable fails with an error message.
-i integer
Certain arithmetic operations are permitted for declared integer variables without the need for expr or let.
-a array
The variable indices will be treated as an array.
-f function(s)
A declare -f line with no arguments in a script causes a listing of all the functions previously defined in that script.
A declare -f function_name in a script lists just the function named.
-x export
This declares a variable as available for exporting outside the environment of the script itself.
-x var=$value
The declare command permits assigning a value to a variable in the same statement as setting its properties.
Example:
Related:
Other Linux Commands:
alias ,
break ,
builtin ,
cal ,
case ,
cat ,
cd ,
cfdisk ,
chgrp ,
chmod ,
chown ,
chroot ,
cksum ,
cmp ,
comm ,
continue ,
cp ,
cron ,
crontab ,
csplit ,
cut ,
date ,
dc ,
dd ,
declare ,
df ,
diff ,
diff3 ,
dir ,
dircolors ,
dirname ,
dirs ,
du ,
echo ,
egrep ,
enable ,
env ,
eval ,
exec ,
expand ,
export ,
expr ,
factor ,
false ,
fdformat ,
fdisk ,
fgrep ,
find ,
fmt ,
fold ,
for ,
fsck ,
function ,
getopts ,
hash ,
hashcharacter ,
head ,
history ,
hostname ,
id ,
if ,
import ,
install ,
join ,
kill ,
less ,
let ,
ln ,
local ,
locate ,
logname ,
logout ,
lpc ,
lpr ,
lprm ,
ls ,
m4 ,
man ,
mbadblocks ,
mkdir ,
mkfifo ,
mknod ,
more ,
mount ,
mtools ,
mv ,
nice ,
nl ,
nohup ,
passwd ,
paste ,
period ,
popd ,
pr ,
printf ,
ps ,
pushd ,
pwd ,
quota ,
quotacheck ,
quotactl ,
ram ,
rcp ,
read ,
readonly ,
return ,
rm ,
rmdir ,
rsync ,
Run ,
sdiff ,
sed ,
select ,
seq ,
set ,
shift ,
shopt ,
shutdown ,
sleep ,
sort ,
split ,
su ,
sum ,
symlink ,
sync ,
tac ,
tail ,
tar ,
tee ,
Test ,
time ,
times ,
top ,
touch ,
tr ,
traceroute ,
true ,
tsort ,
tty ,
Type ,
ulimit ,
umask ,
uname ,
Unexpand ,
uniq ,
units ,
unset ,
unshar ,
until ,
useradd ,
usermod ,
users ,
uuencode ,
watch ,
wc ,
whereis ,
which ,
while ,
who ,
xargs ,
yes ,
Live2Support.com :