LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Pass a variable as an agruement for cut (https://www.linuxquestions.org/questions/programming-9/pass-a-variable-as-an-agruement-for-cut-326992/)

chipmanchu 05-25-2005 10:34 AM

Pass a variable as an agruement for cut
 
I want to pass a variable as an arguement in a cut statement.
Here is basically what I want to do

Opt=3
Optlist="banana apple orange grape"

optsel=`echo $Optlist | cut -d " " -f $Opt`


I want to cut the third field, or what ever Opt is set to at the time, from optsel.
The problem is putting $Opt after -f doesn't work nor does "$Opt", '$Opt'

Can anyone help me.

gerrit_daniels 05-25-2005 11:39 AM

Switch the -f and -d options and it does work.

Code:

optsel=`echo $Optlist | cut -f $Opt -d " "`
Hope this helps


All times are GMT -5. The time now is 09:11 PM.