简体   繁体   English

awk命令未在bash脚本中执行,但在命令行上工作正常

[英]awk command not executed within bash script but works fine on the commandline

I am new to bash scripting. 我是bash脚本的新手。 I am trying to run the following script : 我正在尝试运行以下脚本:

#! /bin/bash

#the following command runs fine within the bash script
awk>/home/Bash_Scripts/filename1 -F, '$3!="constant"{print}' /home/Bash_Scripts/logs.csv

# THE FOLLOWING COMMAND WORKS FINE FROM COMMAND LINE BUT NOT FROM WITHIN BASH SCRIPT

/usr/bin/awk -f /home/Bash_Scripts/process.awk /home/Bash_Scripts/filename1 

Can someone please explain why? 有人可以解释为什么吗? Both are awk commands. 两者都是awk命令。 One works only from commandline and not from within the bash script. 一个只能从命令行运行,而不能从bash脚本中运行。

Thanks in advance. 提前致谢。

Three points: 三点:

  1. You are using /home/Bash_Scripts/filename1 as you output file in the script but as input file in the command line 您正在/home/Bash_Scripts/filename1用作脚本中的输出文件,但用作命令行中的输入文件
  2. /home/Bash_Scripts/logs.csv is your input file in the script. /home/Bash_Scripts/logs.csv是脚本中的输入文件。
  3. You use /usr/bin/awk in the command line but just awk in the script. 您可以在命令行中使用/usr/bin/awk ,但在脚本中仅使用awk This is backwards to what is normally done as you know what PATH is set to in the command line but no idea in general for a script. 这与通常的做法相反,因为您知道在命令行中将PATH设置为什么,但是对于脚本通常没有任何想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM