我要编写一个bash脚本,它返回标题和文档类型以及给定的PDF文件列表中的一些其他内容.所以我试图编写一个函数来获取文档类型.当文档类型为ACM或MIT时,它可以正常工作,但是当输出处于elif块时,它会显示"未找到命令".我的代码在这里 -
#!/bin/bash
function get_type(){
if less "$1" | grep -q -i "ACM TRANSACTIONS"
then
type="ACM Transactions"
elif less "$1" | grep -q -i "journal homepage: www.elsevier.com"
then
type= "ELSEVIER"
elif less "$1" | grep -q -i "IEEE TRANSACTIONS"
then
type= "IEEE Transactions"
else
type="MIT Press"
fi
echo $type
}
for file in ~/Desktop/1105063/papers/*;
do
get_type "$file"
done
Run Code Online (Sandbox Code Playgroud)
这是输出 -
shawon@Shawon-Linux:~/Desktop/1105063$ ./test.sh
./test.sh: line 12: IEEE Transactions: command not found
[...]
Run Code Online (Sandbox Code Playgroud)
请注意,在shell中,空格通常用shell术语来分隔单词.在=
符号周围的变量赋值中必须没有空格.使用
type="IEEE Transactions"
Run Code Online (Sandbox Code Playgroud)
因为
type= "IEEE Transactions"
Run Code Online (Sandbox Code Playgroud)
是type
使用空字符串的一次性赋值,然后尝试执行IEEE Transactions
命令(显然不存在).
归档时间: |
|
查看次数: |
481 次 |
最近记录: |