views:

99

answers:

2

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.

+4  A: 

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.
codaddict
Cheers you have no idea how long I was working on this.
A: 

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

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