cshell脚本中read的问题

leon8023 2007-09-28 04:46:16
请教大家个问题,我使用的环境是IBM服务器,操作系统AIX,写了一个c shell脚本,但是老是出错,哪位高人帮看看,脚本如下(文件名111):
#!/bin/csh
echo abc
read ttt
echo $ttt

执行结果如下:
%csh -xv 111

echo abc^M
echo abc^M
abc
read ttt^M
read ttt^M
/usr/bin/read[53]: ttt^M: is not an identifier
echo $ttt^M
ttt: Undefined variable.
...全文
365 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
leon8023 2007-09-28
  • 打赏
  • 举报
回复
hefuhua 正解,已经解决!谢谢了!
hefuhua 2007-09-28
  • 打赏
  • 举报
回复
From man csh:

$< Substitutes a line from the standard input, with no further
interpretation thereafter. It can be used to read from the
keyboard in a shell script. (+) While csh always quotes $<, as
if it were equivalent to `$<:q', tcsh does not. Furthermore,
when tcsh is waiting for a line to be typed the user may type
an interrupt to interrupt the sequence into which the line is
to be substituted, but csh does not allow this.

http://lists.freebsd.org/pipermail/freebsd-questions/2005-April/083947.html
leon8023 2007-09-28
  • 打赏
  • 举报
回复
晕!那我怎么在csh下输入一个字符呀?
hefuhua 2007-09-28
  • 打赏
  • 举报
回复
在csh里,替代read的用
set aaa=$<
echo $aaa

http://www.lslnet.com/linux/dosc1/20/linux-193251.htm
hefuhua 2007-09-28
  • 打赏
  • 举报
回复
网上说csh没有read 功能
leon8023 2007-09-28
  • 打赏
  • 举报
回复
删除了^M以后,还是不行!执行情况如下:
%111
abc
test
ttt: Undefined variable.
cceczjxy 2007-09-28
  • 打赏
  • 举报
回复
csh -cxv ./111
这样执行就可有了
leon8023 2007-09-28
  • 打赏
  • 举报
回复
不是的,感觉好像是read的语法不对!所以一直很郁闷!
hefuhua 2007-09-28
  • 打赏
  • 举报
回复
vim 打开把^M删除好了
这是dos或windows下的换行符号
或者
dos2unix 111


最好把
chmod a+x 111
为可执行的

cceczjxy 2007-09-28
  • 打赏
  • 举报
回复
不是兼容性的问题吧,
直接 用./111来执行看看.

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧