开发者

Passing Bourne Shell variable into cut command

开发者 https://www.devze.com 2022-12-19 07:32 出处:网络
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.

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

精彩评论

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