由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - 看看我的第一个小script为什么不工作
相关主题
大虾,看看这是咋回子事尼!帮帮忙,用C作一个SHELL
a puzzle!!各位大哥帮忙,EXECVE()的使用
提示我 too many ('s 怎么办?Help wanted for CURSES
How FTP the whole Dir(include Subdir) in UNIX?What's wrong with "CXTERM"CXTERM INSTALL : HELP !
How to program? Shell Question[转载] 再请教高手
Help: wrong operation; mv---->rm.makefile 文件是不是可以看作一种shell?
Re: How to get the name of current executable in a library routine?哪位大虾熟悉gnu的make?
关于emacs一问。[转载] 求救
相关话题的讨论汇总
话题: lastpost话题: answer话题: echo话题: bbs话题: cd
进入Unix版参与讨论
1 (共1页)
t*******l
发帖数: 421
1
要实现下列功能:进入目录bbs,显示所有subdir,从屏幕输入要考古的subdir,
进入该目录,浏览最后一片文章.大致是这样的.
cd bbs
ls
read -p " " answer if ( -e $argv[1]) then
cd $argv[1]
pico lastpost
else
echo2 file $argv[1] doesn't exist
endif
学这个都两星期了,还是创不出来可以执行的小程序来.
请大虾指导指导.
r********s
发帖数: 179
2
your "if...else" grammar seems to be C shell, unfortunately
"read" only works for bourne shell.

【在 t*******l 的大作中提到】
: 要实现下列功能:进入目录bbs,显示所有subdir,从屏幕输入要考古的subdir,
: 进入该目录,浏览最后一片文章.大致是这样的.
: cd bbs
: ls
: read -p " " answer : if ( -e $argv[1]) then
: cd $argv[1]
: pico lastpost
: else
: echo2 file $argv[1] doesn't exist

t*******l
发帖数: 421
3
ah?
I use C shell. then what should I do for the same purpose?

【在 r********s 的大作中提到】
: your "if...else" grammar seems to be C shell, unfortunately
: "read" only works for bourne shell.

C**y
发帖数: 28
4
I think you need to read some csh intro on the internet.
I always forgot those stupid shell grammars, and can program a pretty good
one via the help of google in a short time.

【在 t*******l 的大作中提到】
: ah?
: I use C shell. then what should I do for the same purpose?

r********s
发帖数: 179
5
[10:45pm] cat hoho.sh
#!/bin/sh
cd bbs
ls
echo -n "Which directory you wanna browse:\t "
read answer
if [ -d $answer ]
then
cd $answer
echo "The content of lastpost is:\n"
echo "******"
cat "/home/rhino/bbs/$answer/lastpost"
echo "******"
else
echo "$answer directory does not exitst!"
fi
[10:45pm] ls -R bbs
family love sysop
bbs/family:
lastpost
bbs/love:
lastpost
bbs/sysop:
lastpost
[10:46pm] ./hoho.sh
family love s

【在 t*******l 的大作中提到】
: ah?
: I use C shell. then what should I do for the same purpose?

t*******l
发帖数: 421
6
thanks rhinoceros!
我又扩展了一下。如果/bbs/boards/family/里有吃,穿,住,用,行中的
若干项,是不是意味着要多几个if语句,以相同的格式?
我刚刚这样试了一下,不行:(
#!/bin/sh
cd bbs
ls
echo -n "Which directory you wanna browse:\t "
read answer
if [ -d $answer ]
then
cd $answer
echo "The content of lastpost is:\n"
echo "******"
cat "/home/rhino/bbs/$answer/lastpost"
echo "******"
else
if [ -d $answer2 ]
then
cd $answer2
ls
if [ -d $answer3 ]
then
cd $answer3
ls


【在 r********s 的大作中提到】
: [10:45pm] cat hoho.sh
: #!/bin/sh
: cd bbs
: ls
: echo -n "Which directory you wanna browse:\t "
: read answer
: if [ -d $answer ]
: then
: cd $answer
: echo "The content of lastpost is:\n"

r********s
发帖数: 179
7

also remember you need a "fi" as the end of testing structure

【在 t*******l 的大作中提到】
: thanks rhinoceros!
: 我又扩展了一下。如果/bbs/boards/family/里有吃,穿,住,用,行中的
: 若干项,是不是意味着要多几个if语句,以相同的格式?
: 我刚刚这样试了一下,不行:(
: #!/bin/sh
: cd bbs
: ls
: echo -n "Which directory you wanna browse:\t "
: read answer
: if [ -d $answer ]

r********s
发帖数: 179
8
if condition1
then
command list if condition1 is true
[elif condition2
then command list if condition2 is true]
[else
command list if condition1 is false]
fi
FYI, the above shows the nested conditional structure.

【在 r********s 的大作中提到】
:
: also remember you need a "fi" as the end of testing structure

f***y
发帖数: 98
9
yeah....
remove the line "read answer"
replace $answer, $answer2, $answer3 with $1, $2, $3...

【在 r********s 的大作中提到】
: if condition1
: then
: command list if condition1 is true
: [elif condition2
: then command list if condition2 is true]
: [else
: command list if condition1 is false]
: fi
: FYI, the above shows the nested conditional structure.

1 (共1页)
进入Unix版参与讨论
相关主题
[转载] 求救How to program? Shell Question
[转载] Shell高手看过来。Help: wrong operation; mv---->rm.
[转载] qestion about grepRe: How to get the name of current executable in a library routine?
Re: ctrl+c doesn't work in csh, (solved)关于emacs一问。
大虾,看看这是咋回子事尼!帮帮忙,用C作一个SHELL
a puzzle!!各位大哥帮忙,EXECVE()的使用
提示我 too many ('s 怎么办?Help wanted for CURSES
How FTP the whole Dir(include Subdir) in UNIX?What's wrong with "CXTERM"CXTERM INSTALL : HELP !
相关话题的讨论汇总
话题: lastpost话题: answer话题: echo话题: bbs话题: cd