我从来没有使用shell脚本,但现在我必须,这是我正在尝试做的事情:
#!/bin/bash
echo running the program
./first
var = ($(ls FODLDER |wc -l)) #check how many files the folder contains
echo $var
if( ["$var" -gt "2"] #check if there are more the 2file
then ./second
fi
Run Code Online (Sandbox Code Playgroud)
scriopt在if声明中崩溃了.我怎么能解决这个问题
许多:
var = ($(ls FODLDER |wc -l))
Run Code Online (Sandbox Code Playgroud)
这是错误的,你不能有这些空间=.
if( ["$var" -gt "2"]
Run Code Online (Sandbox Code Playgroud)
你(没有做任何事情,所以必须删除它.此外,你需要[和周围的空间].
总之,这将更有意义:
#!/bin/bash
echo "running the program"
./first
var=$(find FOLDER -maxdepth 1 -type f|wc -l) # better find than ls
echo "$var"
if [ "$var" -gt "2" ]; then
./second
fi
Run Code Online (Sandbox Code Playgroud)
注意:
echo,特别是处理变量时.| 归档时间: |
|
| 查看次数: |
50 次 |
| 最近记录: |