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
精彩评论