使用COMM和SORT的Bash脚本在意外令牌附近发出语法错误 [英] Bash script using COMM and SORT issues syntax error near unexpected token

查看:69
本文介绍了使用COMM和SORT的Bash脚本在意外令牌附近发出语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux,CentOS-比较我使用命令的2个文件

Linux, CentOS - to compare 2 files I use command

comm --check-order -1 --output-delimiter=----- <sort(file1.txt) <sort (file3.txt) > result.txt ;

它可以在shell上运行,但是当我尝试创建bash文件时-我有

and it works on shell, but when I try create a bash file - I have

syntax error near unexpected token `('

脚本最简单

#!/bin/bash
cd /var/www/html/compare/ ;
comm --check-order -1 --output-delimiter=----- <sort(file1.txt) <sort (file3.txt) > result.txt ;
exit ;
    sh

我已经尝试过用圆括号转义的变体,例如

I already tried variations with escaping of round brackets like

sort\(file1.txt\)

sort'(file1.txt)'

但是这种情况下壳说

sort(file1.txt)...: No such file or directory

我尝试了像这样的绝对路径

I tried with absolute path like

<sort\(var/www/html/compare/file1.txt\)

相同的结果没有这样的文件"

same result "No such file"

并且我已经尝试使用类似的变体来运行脚本

and I already tried run the script with variations like

sh /a/compare.sh
bash /a/compare.sh
chmod +x /a/compare.sh; ./a/compare.sh

还是同样的问题.

因此,我有没有这样的文件..."或带括号的转义符-或在其他情况下为意外的令牌".

So I have OR "No such file..." with escaping of brackets - OR "unexpected token"in other cases.

预先感谢任何尝试的想法,可能应该是语法的正确组合"吗?

Thanks in advance for any ideas to try, may be should be a right "mix" of syntax ?

推荐答案

经过多次组合,我找到了一种解决方案,我们需要使用一些特殊的转义来强制BASH.该脚本有效

After many combinations I found the solution where we need to force BASH with a little specific escaping. This script works

#!/bin/bash
cd /var/www/html/compare/ ;
`bash -c "comm --check-order -1 --output-delimiter=----- <(sort file1.txt) <(sort file2.txt) > result.txt" ` ;
exit ;
    sh

希望能帮助别人节省时间.

Hopefully will help somebody to save the time.

这篇关于使用COMM和SORT的Bash脚本在意外令牌附近发出语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆