命名管道的标识符无效 ... "not a valid identifier"
Invalid identifier for named pipe ... "not a valid identifier"
我有以下创建命名管道的调用:
mkfifo "$HOME/.quicklock/ql_named_pipe";
然后我从命名管道读取:
while read line; do ql_on_named_pipe_msg "$line" "$$"; done < "$HOME/.quicklock/ql_named_pipe" &
但我收到此错误消息:
./scripts/tsc.sh: line 23: read:
`/Users/alexamil/.quicklock/ql_named_pipe': not a valid identifier
有人知道为什么这不起作用吗?
不确定问题出在哪里,但这应该可以正常工作:
my_named_pipe="/some/path/on/your/fs/ql_named_pipe"
while read line; do ql_on_named_pipe_msg "$line" "$$"; done < ${my_named_pipe} &
如果仔细阅读评论,原来的代码是这样的:
my_named_pipe="$HOME/.quicklock/ql_named_pipe"
…
while read $my_named_pipe
do
…
done < $my_named_pipe # This redirection not 100% clearly stated
这确实会导致错误 'invalid identifier'。 read
命令期望被赋予变量名作为参数。当给出 $my_named_pipe
时,它会看到:
while read /Users/whoever/.quicklock/ql_named_pipe
这绝对是不是有效的变量名。
如 中所提议,最合理的替代方案是:
while read line
do
…
done < $my_named_pipe
'mostly' 存在是因为 read
in the POSIX sh
— see also the Bash manual for read
存在问题。您可能更喜欢使用 read -r
(或者再次使用,也许您不会)。
我有以下创建命名管道的调用:
mkfifo "$HOME/.quicklock/ql_named_pipe";
然后我从命名管道读取:
while read line; do ql_on_named_pipe_msg "$line" "$$"; done < "$HOME/.quicklock/ql_named_pipe" &
但我收到此错误消息:
./scripts/tsc.sh: line 23: read: `/Users/alexamil/.quicklock/ql_named_pipe': not a valid identifier
有人知道为什么这不起作用吗?
不确定问题出在哪里,但这应该可以正常工作:
my_named_pipe="/some/path/on/your/fs/ql_named_pipe"
while read line; do ql_on_named_pipe_msg "$line" "$$"; done < ${my_named_pipe} &
如果仔细阅读评论,原来的代码是这样的:
my_named_pipe="$HOME/.quicklock/ql_named_pipe"
…
while read $my_named_pipe
do
…
done < $my_named_pipe # This redirection not 100% clearly stated
这确实会导致错误 'invalid identifier'。 read
命令期望被赋予变量名作为参数。当给出 $my_named_pipe
时,它会看到:
while read /Users/whoever/.quicklock/ql_named_pipe
这绝对是不是有效的变量名。
如
while read line
do
…
done < $my_named_pipe
'mostly' 存在是因为 read
in the POSIX sh
— see also the Bash manual for read
存在问题。您可能更喜欢使用 read -r
(或者再次使用,也许您不会)。