Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 如何循环脚本直到用户输入为空?_Shell_Loops_While Loop_Csh - Fatal编程技术网

Shell 如何循环脚本直到用户输入为空?

Shell 如何循环脚本直到用户输入为空?,shell,loops,while-loop,csh,Shell,Loops,While Loop,Csh,我试图让我的脚本重复,直到用户将区块问题留空。我刚让循环运行,但我找不到一种方法,使它在块为空时停止 我希望有人能帮助我 #!/bin/tcsh -f # set word="start" until ($word !=""); do #First ask for Compound and Block Name. echo -n "please enter block name: " read block echo -n "please enter compound name: " read

我试图让我的脚本重复,直到用户将区块问题留空。我刚让循环运行,但我找不到一种方法,使它在块为空时停止

我希望有人能帮助我

#!/bin/tcsh -f
#

set word="start"
until ($word !=""); do

#First ask for Compound and Block Name.
echo -n "please enter block name: "
read block
echo -n "please enter compound name: "
read compound

#Now coping template with new name
#
cp Template $block
#
        for line  in `cat $block`;do
        echo $line | sed -e "s/test1/${block}/g" -e "s/test2/${compound}/g" >>./tmp124.txt
done

mv ./tmp124.txt $block

done

您想使用bash还是csh?您使用的是bash语法,但在代码的第一行中标记了问题csh并调用tcsh

为了回答您的问题,以下是如何迭代标准输入直到某个输入为空的示例:

对于tcsh:

#!/bin/tcsh

while ( 1 )
    set word = "$<"
    if ( "$word" == "" ) then
        break
    endif

    # rest of code...
end

请始终显示错误消息!为什么要让我们猜?很抱歉给您带来不便。我的错误是:第20行出现语法错误:“文件结尾”意外。
#!/bin/bash

while read word; do
    if [ -z $word ]; then
        break
    fi

    # rest of code...
done