LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 07-15-2005, 11:10 AM   #1
arosales
LQ Newbie
 
Registered: Jul 2005
Posts: 2

Rep: Reputation: 0
parsing standard input with bash


Hi! I'm trying to set a variable with the standard input but i have a problem. For example:

user@work005:~> input some command done by me with ten parameters or more

In mi bash script I have
....
field1=$1
field2=$2 ...
field10=$10
--------------------

fields 1 to 9 i don't have troubles, but field 10 sets "$field1"0, it means

....
field1=input
field2=some...
field10=input0
----------------------

and I need filed10=or

What should I do? Thanks in advance...



Last edited by arosales; 07-15-2005 at 11:20 AM.
 
Old 07-15-2005, 11:15 AM   #2
arosales
LQ Newbie
 
Registered: Jul 2005
Posts: 2

Original Poster
Rep: Reputation: 0
RE: parsing standard input with bash

I just have to enclosed it in {brackets}

field10=${10}

field10=or

(I have to read more before post)

Last edited by arosales; 07-15-2005 at 11:21 AM.
 
Old 07-15-2005, 11:26 AM   #3
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
If the number of positional parameters ($#) is greater than 9, then you can use the 'shift' bash command to get the remaining parameters. See 'man bash' for details. For example:

field1=$1
field2=$2...
field9=$9
shift 9
field10=$1
field11=$2...

Last edited by macemoneta; 07-15-2005 at 11:27 AM.
 
Old 07-16-2005, 10:42 AM   #4
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Re: parsing standard input with bash

Quote:
Originally posted by arosales
Hi! I'm trying to set a variable with the standard input but i have a problem.
To be pedantic, you're not setting your variables from standard input, but from command line parameters.
 
  


Reply



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
Standard Input in Perl Program eachow Linux - General 2 11-17-2005 12:16 AM
utf , standard output / input and grep too Fascistchicken Linux - Software 2 11-05-2004 08:52 AM
parsing a user input string daphne19 Programming 1 04-22-2004 07:40 AM
my mouse input is takes as keyboard input in BASH e1000 Slackware 5 12-08-2003 03:00 PM
stty: standard input: Inappropriate ioctl for device fwalthard Linux - General 0 07-14-2003 02:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration