LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-25-2005, 10:34 AM   #1
chipmanchu
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

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

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

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


Reply


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


All times are GMT -5. The time now is 03:14 AM.

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