[-f: Command not found, Bash script does file exist
本问题已经有最佳答案,请猛点这里访问。
我正在尝试编程的脚本有问题。缩小并简化了代码,它给出了一个错误,即找不到命令。如果我在命令行中执行"test-f file",它将返回Nothing,Not command not found
1 2 3 4 5 6 7 8 9 10 11 | PATH=$1 #!/bin/bash DIR=$1 if [[-f $PATH]]; then echo expression evaluated as true else echo expression evaluated as false fi exit |
下面是我要运行的更复杂的脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | verify() { if [[-f $1]]; then VFY[$2]="f" echo"$1 is a file" elif [[-d $1]] then VFY[$2]="d" echo"$1 is a directory" else VFY[$2]=0 echo -e" " echo"$1 is neither a file or a directory" echo -e" " fi } |
号
它是一个更大的脚本的一部分,可以根据输入移动内容。我在Centos6和FreeBSD中运行过,它们都给出了相同的错误"[-f:command not found"
只需在
你会得到:
1 2 3 4 5 6 7 8 9 | #! /bin/bash DIR=${1-} # unused in your example if [[ -f test.sh ]]; then echo"expression evaluated as true" else echo"expression evaluated as false" fi exit |
为了你的职责
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | verify() # file ind { local file=$1 ind=$2 if [[ -f"$file" ]]; then VFY[ind]="f" # no need of $ for ind echo"$file is a file" elif [[ -d"$file" ]]; then VFY[ind]="d" echo"$file is a directory" else VFY[ind]=0 echo -e" $file is neither a file or a directory " fi } |
号