Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-25-2005, 10:34 AM   #1
LQ Newbie
Registered: May 2005
Posts: 1

Rep: Reputation: 0
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

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.
Old 05-25-2005, 11:39 AM   #2
Registered: Oct 2003
Location: Belgium
Distribution: Kubuntu
Posts: 34

Rep: Reputation: 15
Switch the -f and -d options and it does work.

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass object variable to anothor class in JAVA hus Programming 2 05-11-2005 04:04 AM
How to pass mysql query to a variable? chynna_v Programming 4 09-03-2004 05:09 AM
How to pass env variable to KDE? koyi Linux - General 0 09-03-2003 03:29 AM
How do I pass a C variable to a Bash command ? Linh Programming 6 07-07-2003 03:12 PM
Pass text to variable Zed Linux - Software 6 05-12-2003 03:02 PM > Forums > Non-*NIX Forums > Programming

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration