I am trying to assign output of a cut command to a variable, however I am running into a strange problem. I am using tcsh shell.
我试图将cut命令的输出分配给变量,但是我遇到了一个奇怪的问题。我正在使用tcsh shell。
$echo $0
tcsh
This is the command I am running:
这是我正在运行的命令:
$set a=`cut -f2 -d' ' test.txt`
Missing }. //This is the output I am getting
Now the file is real simple (well this is the not the file I was working on but I reduced the problem to this.)
现在该文件非常简单(这不是我正在处理的文件,但我将问题减少到了这一点。)
Test.txt:
{ {corner
Thats it! This is the file. If I change the file to this:
而已!这是文件。如果我将文件更改为:
{ {corner}
Statement works but "a" gets the following value:
声明有效,但“a”获得以下值:
$echo $a
corner //Please note its not {corner} but corner
Hence I think that shell is trying to execute {corner
as a command and since its missing the closing brace shell complains. Does anyone have any idea why its showing this behavior? My understanding is that it should just assign the output of cut to the variable but looks like its assigning it recursively! Newbie
因此我认为shell正在尝试执行{corner as a command,因为它缺少关闭括号shell抱怨。有没有人知道为什么它会出现这种行为?我的理解是它应该只将cut的输出分配给变量,但看起来像递归分配它!新手
1 个解决方案
#1
5
You have to wrap it around double quotes
你必须用双引号括起来
set a="`cut -f2 -d' ' test.txt`"
Same applies to uses such as echo
同样适用于回声等用途
echo "$a"
Output
{corner
#1
5
You have to wrap it around double quotes
你必须用双引号括起来
set a="`cut -f2 -d' ' test.txt`"
Same applies to uses such as echo
同样适用于回声等用途
echo "$a"
Output
{corner