为什么我的declare 指令在shell中是not found,但是在bash中却可以

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
yutuer
帖子: 12
注册时间: 2009-02-11 8:56

为什么我的declare 指令在shell中是not found,但是在bash中却可以

#1

帖子 yutuer » 2009-04-15 12:49

shell中想用declare -i 来声明整形,但是老是说not found,但是在bash中却是正常的
头像
懒蜗牛Gentoo
论坛版主
帖子: 7353
注册时间: 2007-03-02 17:36
系统: Linux Mint

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#2

帖子 懒蜗牛Gentoo » 2009-04-15 13:02

那你说的在shell中可以是在哪个shell中?
虽然世上没有完美的东西,但这并不影响我们追求完美,因为只有偏执狂才TMD能成功。
10.04新手入门——笨兔兔讲述自己的故事
yutuer
帖子: 12
注册时间: 2009-02-11 8:56

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#3

帖子 yutuer » 2009-04-15 13:19

就是自己写的一个脚本
#!/bin/bash
declare -i s=3*6;
echo $s;

奇怪的是,我用./文件名 是可以执行的,但是用sh 文件名,就会出现declare not found 的情况
头像
wangdu2002
帖子: 13284
注册时间: 2008-12-13 19:39
来自: 物华天宝人杰地灵

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#4

帖子 wangdu2002 » 2009-04-15 13:23

应该是路径设置问题。 :em06
行到水穷处,坐看云起时。
海内生明月,天涯共此夕。
--------------------吾本独!
‏‫‮
帖子: 38
注册时间: 2008-06-09 1:27

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#5

帖子 ‏‫‮ » 2009-04-15 13:25

默认的shell是bash么...

代码: 全选

ls -l /bin/sh
yutuer
帖子: 12
注册时间: 2009-02-11 8:56

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#6

帖子 yutuer » 2009-04-15 13:29

应该是的把,ls了一下
lrwxrwxrwx 1 root root 4 2009-03-21 07:55 /bin/sh -> dash
这样的
yutuer
帖子: 12
注册时间: 2009-02-11 8:56

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#7

帖子 yutuer » 2009-04-15 13:44

同样,我直接使用 /bin/sh 文件名,也是not found
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#8

帖子 xhy » 2009-04-15 14:16

yutuer 写了:应该是的把,ls了一下
lrwxrwxrwx 1 root root 4 2009-03-21 07:55 /bin/sh -> dash
这样的

dash不是bash 差别太大了
目前负债150多万
yutuer
帖子: 12
注册时间: 2009-02-11 8:56

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#9

帖子 yutuer » 2009-04-15 16:18

那怎么样改才能让我能用sh 文件名
来执行shell脚本呢?
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#10

帖子 xhy » 2009-04-15 16:26

yutuer 写了:那怎么样改才能让我能用sh 文件名
来执行shell脚本呢?

把指向dash的sh改成指向bash
目前负债150多万
yutuer
帖子: 12
注册时间: 2009-02-11 8:56

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#11

帖子 yutuer » 2009-04-15 16:44

好了,谢谢xhy
那为什么sh最开始会是指向dash的呢?

还有,我开始不是加了#!/bin/bash吗,有什么用处阿
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#12

帖子 xhy » 2009-04-15 17:50

yutuer 写了:好了,谢谢xhy
那为什么sh最开始会是指向dash的呢?

还有,我开始不是加了#!/bin/bash吗,有什么用处阿
如果你用sh xxx的命令执行,那么第一行的 #!/bin/bash 就被无视了

如果是 chmod +x xxx.sh
再用 ./xxx.sh执行 shell会分析文件的首行,根据那个调用解释器
目前负债150多万
yutuer
帖子: 12
注册时间: 2009-02-11 8:56

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#13

帖子 yutuer » 2009-04-17 13:47

xhy 写了:
yutuer 写了:好了,谢谢xhy
那为什么sh最开始会是指向dash的呢?

还有,我开始不是加了#!/bin/bash吗,有什么用处阿
如果你用sh xxx的命令执行,那么第一行的 #!/bin/bash 就被无视了

如果是 chmod +x xxx.sh
再用 ./xxx.sh执行 shell会分析文件的首行,根据那个调用解释器

彻底明白了,太谢谢鸟
luber
帖子: 19
注册时间: 2008-08-27 17:04

Re: 为什么我的declare 指令在shell中是not found,但是在bash中却可以

#14

帖子 luber » 2009-05-24 13:20

修改 sh 的命令 sudo dpkg-reconfigure dash/bash
回复