Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Can';t在脚本中运行函数_Bash - Fatal编程技术网

Bash Can';t在脚本中运行函数

Bash Can';t在脚本中运行函数,bash,Bash,我的问题是无法运行函数order\u sessions() 我已经知道我是否有别名,但我没有。我正在运行较新的MacOS,但我已经在Linux中尝试过了 #!/bin/bash path="/var/log/wtmp" file_array=() function read_file(){ while IFS= read -r line; do file_array+=("$line") done < "$path" } read_file() fu

我的问题是无法运行函数order\u sessions()

我已经知道我是否有别名,但我没有。我正在运行较新的MacOS,但我已经在Linux中尝试过了

#!/bin/bash

path="/var/log/wtmp"

file_array=() 

function read_file(){
    while IFS= read -r line; do 
    file_array+=("$line")
    done < "$path"  
}
read_file()

function order_sessions(){
    case $2 in

    -r)
        statements ;;
    -n )
        statements ;;
    -t )
        statements ;;
    -a )
        statements ;;
    -i )
        statements ;;

esac
}


case $1 in

      )
      if [![ -z "$2" ]]
      then
      fi
        statements ;;
    -g )
        statements ;;
    -u )
        statements ;;
    -s )
        statements ;;
    -e )
        statements ;;
    -f )

        path = $2
        read_file() ;;
esac

read_file()
中删除括号,谢谢Darren。另外,如何将带有空字符串的选项放入带有$1变量的开关中?因为我使用的方式是错误的……您所有的问题都将由回答。请注意,MacOS包含bash的旧版本3.2.57,它缺少很多功能。自从bash将其许可证升级到GPLv3后,苹果就不被法律允许包含较新版本的bash,这与苹果的封闭源代码理念不兼容。
./userstats.sh: line 18: syntax error near unexpected token `function'
./userstats.sh: line 18: `function order_sessions(){'