Bash Can';t在脚本中运行函数
我的问题是无法运行函数order\u sessions() 我已经知道我是否有别名,但我没有。我正在运行较新的MacOS,但我已经在Linux中尝试过了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
#!/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(){'