shell script: bad interpreter: No such file or directory when using pwd

后端 未结 11 1786
抹茶落季
抹茶落季 2021-02-07 09:30

I want to go through the files in a directory with a for loop but this comes up.

echo: bad interpreter: No such file or directory

code:

11条回答
  •  不要未来只要你来
    2021-02-07 10:00

    Better do :

    #!/bin/bash
    count=0
    dir="$PWD"
    echo "$dir"
    
    for file in "$dir"/*
    do
     if [[ -f $file ]]
     then
      ((count++))
     fi
    done
    echo $count
    

    or a simplest/shortest solution :

    #!/bin/bash
    
    echo "$PWD"
    
    for file; do
     [[ -f $file ]] && ((count++))
    done
    
    echo $count
    

提交回复
热议问题