首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >1)文件列表脚本中的case语句中出现简单脚本错误

1)文件列表脚本中的case语句中出现简单脚本错误
EN

Stack Overflow用户
提问于 2013-11-21 02:10:54
回答 1查看 68关注 0票数 0

我真的找不到一个和这个类似的线程,所以我想我应该创建一个新的线程。我正在尝试创建一个基本的bash脚本,该脚本一次显示当前目录中一个文件的名称。

一个echo语句说“你想预览这个文件吗?是/否”,如果是,那么代码继续使用head语法显示该文件的前3行,然后程序退出。

到目前为止,这就是我的想法,

代码语言:javascript
复制
#!/bin/bash
for file in ./* #This points to current directory with ./* and views files inside.
do
    if [[ -f $file ]] #If File Exists, read it
            read file
    then
            echo -e 'Would you like to view this file? Press 1 For Yes and 2 For No'
            read boolean #reads the prompt 1 or 2 to then proceed with the case              statement below
    case $boolean
    1)
            echo -e 'Preview of File...'
            read boolean
            2)
            echo -e 'Exit Program...'
            read boolean
    if [ boolean -eq 1 ] #This part of the code finds out if the prompt was answered with 1 (yes), if it was then it produces the first 3 lines of the file, if it was 2 then it quits the program.
    then line=$(head -n 3 file)
    else
    *( echo -e 'Please enter a valid option' #If someone enters 3-9 then the program will require them to enter a valid number.
    esac
    done
    fi

在启动case语句之后,程序在第23行"1)“处显示错误。这不是正确的语法吗?我不太确定为什么它会这么做。

EN

回答 1

Stack Overflow用户

发布于 2013-11-21 02:13:16

首先,你错过了in

代码语言:javascript
复制
case "$boolean" in
    1)

第二,你错过了;;

代码语言:javascript
复制
read boolean ;;

另外,引用你的变量。似乎还有其他错误。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20103629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档