开发者

Passing Bourne Shell variable into cut command

I am trying to do the following.

foo="foo:foo1"
cc= `$foo | cut -f2 -d:`

I开发者_如何学编程 understand why this would not work but I am at a loss as to do this.

Thanks in advance.


Try this:

foo="foo:foo1"
cc=`echo $foo | cut -f2 -d:`

There are 2 changes to make:

  • You need to echo the value of shell variable foo and then cut it.
  • You must not have white spaces around = when assigning a value to a shell variable.


in bourne, you can use set. No external command needed.

$ foo="foo:foo1"
$ IFS=":"
$ set -- $foo
$ echo $2
foo1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜