【发布时间】:2015-08-14 12:06:35
【问题描述】:
我使用带有 shell 脚本的 ls 编写了一个非常简单的文件浏览器。我使用了一个 while 循环来使脚本永远运行(直到 Ctrl+C),但是 while 循环似乎不起作用。我收到此错误
./fileexplorer: line 5: syntax error near unexpected token `done'
./fileexplorer: line 5: `done'`
我的代码是这样的:
#!/bin/bash
ls -l $1
while :
browse()
done
function browse()
{
read file;
if [ -f $file ]
if test -e $file
echo "Starting $file with nano."
echo "Press a key to open the file."
pause
nano $file
if test -d $file
ls -l $file
}
【问题讨论】:
-
将代码粘贴到shellcheck.net
标签: bash while-loop