发新话题
打印

[常用命令] declare???

declare???

tracydundun@tracydundun-laptop:~/scripts$ number=2*3-3
tracydundun@tracydundun-laptop:~/scripts$ echo $number
2*3-3
tracydundun@tracydundun-laptop:~/scripts$ echo "$number"
2*3-3
tracydundun@tracydundun-laptop:~/scripts$ declare -i number=2*2-1
tracydundun@tracydundun-laptop:~/scripts$ echo $number
3
tracydundun@tracydundun-laptop:~/scripts$ more declare.sh
#writen at 7.2
#for declare
numebr1=2*3+2*3-4
declare number2=2*3+2*3-4
echo $number1
echo $number2
tracydundun@tracydundun-laptop:~/scripts$ sh declare.sh
declare.sh: 4: declare: not found

please tell me why "declare.sh:4:declare:not found"
thak you!!

TOP

declare后面要加数据类型
复制内容到剪贴板
代码:
declare -i number2=2*3+2*3-4

TOP

回复 2楼 grassofhust 的帖子

Thank you !
But when I add the "-i" to it,the result is also wrong!

TOP

有哪不对劲吗?
贴代码看看

TOP

回复 4楼 grassofhust 的帖子

tracydundun@tracydundun-laptop:~/scripts$ more declare.sh
#writen at 7.2
#for declare
numebr1=2*3+2*3-4
declare -i number2=2*3+2*3-4
echo $number1
echo $number2
tracydundun@tracydundun-laptop:~/scripts$ sh declare.sh
declare.sh: 4: declare: not found


tracydundun@tracydundun-laptop:~/scripts$

TOP

你用的什么shell
我这边bash是没有问题的。
复制内容到剪贴板
代码:
file $(which sh)

TOP

tracydundun@tracydundun-laptop:~$ echo $0
bash
The same as yours!

TOP

复制内容到剪贴板
代码:
type declare
你这个declare是用的内部命令吗?
numebr1=2*3+2*3-4
这个应该是写错了吧,number1

TOP

发新话题