English 中文(简体)
千兆瓦变量
原标题:Messy bash variable
  • 时间:2010-03-18 18:19:20
  •  标签:
  • bash
  • awk

I m 书写字,在机器清单中添加,将变数与另一个数值进行比较。 我已陷入了一个问题(我有双管齐下的工作,但此时我只想为什么这一方法不起作用)。

VAR=`ssh $i "awk -F:  /^bar/ {print $2}  /local/foo.txt"`

(一) 姓名。 东道方得到信任,没有发出密码。

例如:

foo:123456:abcdef
bar:789012:ghijkl
baz:345678:mnopqr

我假定它带有引语或需要某些地方的问题。 我尝试了几种方法(不同的引用,使用(......)美元而不是“......”等),但似乎无法做到。 我的文字正在正确使用以下文字:

VAR=`ssh $i "grep bar /local/foo.txt" | awk -F:  {print $2} `

和我一样,只要是好奇,任何反应都会受到赞赏。

想说我的产出是什么:一夫一把整个配对线,而不是第二段。 我在引用和照搬字面时,似乎对“......没有发现的指挥”产生错误,因为那里有一条新线。

最佳回答

粉碎使你指挥下方能够执行,因此,它穿过边远方的巴什口译员以及你执行该笔文字的一方。 请看一下你的指挥:

VAR=`ssh $i "awk -F:  /^bar/ {print $2}  /local/foo.txt"`

您已适当逃脱了当地机器的<代码>2,这样,你重新执行的印本不会解释。 但是,所有引文都在 by到w子时被删除(我并不完全确定内部引文为何被删除),并且执行:

awk -F: /^bar/ {print $2} /local/foo.txt

b 边远边的ash有2美元,用空洞取代。

awk -F: /^bar/ {print } /local/foo.txt

因此,它印刷了整个线。 因此,你如何确定这一点? 你们可以躲避边边边边边边边边的ash子,像这样:

VAR1=`ssh $i localhost "echo awk -F:  /^bar/ {print \$2}  /local/foo.txt"`

此外,你也只能同大家一样,看到你真心实意地执行什么,以缓解你面临的任何进一步问题:

VAR1=`ssh $i localhost "echo awk -F:  /^bar/ {print $2}  /local/foo.txt"`
echo VAR1: $VAR1

Execute it and see this output and see right away that it has removed $2:
VAR1: awk -F: /^bar/ {print } /local/foo.txt
问题回答

尽可能使用<代码>$()

VAR=$(ssh $i "awk -F:  /^bar/ {print $2}  /local/foo.txt")




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签