求指点。关于shell

sh/bash/dash/ksh/zsh等Shell脚本
回复
asianWang
帖子: 14
注册时间: 2012-04-12 16:58

求指点。关于shell

#1

帖子 asianWang » 2012-04-17 13:01

ubuntu11.10,shell是不是不支持break跟continue啊,而且,那个shell高级编程里面好多再ubuntu的shell下不成立是不是?
asianWang
帖子: 14
注册时间: 2012-04-12 16:58

Re: 求指点。关于shell

#2

帖子 asianWang » 2012-04-17 13:07

#!/bin/bash

read -p "Press a key: " keypress
while [ "$keypress" != 'X' ]
do
case $keypress in
[0-9])
echo "Digit."
*)
echo "Punctuation."
esac
read -p "Press a key: " keypress
echo
done

exit 0
就这个就运行了半天都是错的。。。无语了。。。
~
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 求指点。关于shell

#3

帖子 lilydjwg » 2012-04-17 13:12

  1. 贴代码记得点下工具栏的 Code 标签
  2. 我们视力正常,请使用正常大小的文本,谢谢
  3. 不要随便怀疑你的工具,先怀疑你的代码。(因为格式太乱,我没有看你贴的代码,但我注意到你放大的文本中有错别字。)
头像
b33e
帖子: 3874
注册时间: 2011-06-07 14:20

Re: 求指点。关于shell

#4

帖子 b33e » 2012-04-17 13:44

错误提示里面应该很清楚啊。看看你的是不是字母写错了什么的?
[bash]#!/bin/bash

read -p "Press a key: " keypress
while [ "$keypress" != 'X' ]
do
case $keypress in
[0-9])
echo "Digit."

echo "Punctuation."
esac
read -p "Press a key: " keypress
echo
done

exit 0[/bash]
上次由 b33e 在 2012-04-17 14:31,总共编辑 2 次。
头像
link_01
帖子: 1024
注册时间: 2008-11-05 13:24

Re: 求指点。关于shell

#5

帖子 link_01 » 2012-04-17 13:57

我按着LZ的内容手动输入了一遍,执行没有错误,再复制粘贴运行报错 line 9,原来case的块不符合语法结构;
看看我不假思索地多输入了两个分号,哎,怨天尤人不如求己啊。
[bash]#!/bin/bash

read -p "Press a key: " keypress
while [ "$keypress" != 'X' ]
do
case $keypress in
[0-9])
echo "Digit."
;; #./t.sh: line 9: syntax error near unexpected token `)'
*)
echo "Punctuation."
esac
read -p "Press a key: " keypress
echo
done

exit 0
[/bash]
上次由 link_01 在 2012-04-17 14:03,总共编辑 1 次。
笔记
-------------------------------------
http://blog.163.com/wqt_1101
asianWang
帖子: 14
注册时间: 2012-04-12 16:58

Re: 求指点。关于shell

#6

帖子 asianWang » 2012-04-17 14:00

没有太试用过论坛,所以不懂规矩,忘各位老大见谅,而且听了第一位仁兄的话以后赶紧回去找错误,已经发现错误之处了。还有就是楼上的人真是……怪你手贱……你厉害 :em20
头像
枫叶饭团
帖子: 14683
注册时间: 2010-06-16 1:05
系统: Mac OS X
来自: Tencent
联系:

Re: 求指点。关于shell

#7

帖子 枫叶饭团 » 2012-04-17 15:41

shell语法对新手来说是有点蛋疼,不过蛋疼的地方也就。那么几个
回复