declare [-aAfFilrtux] [-p] [name[=value] ...]
$ declare -r Vareadonly=only
$ echo $Vareadonly
only
$ Vareadonly=you
bash: Vareadonly: readonly variable
$ declare -i integer=a
$ echo $integer
0
$ integer=8
$ echo $integer
8
#!/bin/bash
declare -a array
let i=0
while [ $i -lt 5 ]
do
array[$i]=$i
(( i++ ))
done
echo ${array[@]}
exit 0
$ sh declare.sh
0 1 2 3 4
#!/bin/bash
ARGS=2
E_WRONGARGS=65
if [ $# -ne "$ARGS" ]
then
echo "Usage: `basename $0` filename column-number"
exit $E_WRONGARGS
fi
filename=$1
column_number=$2
export column_number
awkscript='{total += $ENVIRON["column_number"]}
END { print total }'
awk "$awkscript" "$filename"
exit 0
$ cat test.txt
1 3
2 5
11 6
33 56
21 26
12 53
$ ./exp.sh test.txt 1
80
$ ./exp.sh test.txt 2
149
#!/bin/bash
declare -l str1="HELLO"
declare -u str2="world"
echo $str1 $str2
$ sh exp3.sh
hello WORLD
#!/bin/bash
func1()
{
echo "hello world"
}
func2()
{
echo "how are you"
}
declare -f
exit 0
$ sh exp4.sh
func1 ()
{
echo "hello world"
}
func2 ()
{
echo "how are you"
}
$sh exp4.sh
declare -f func1
declare -f func2
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |