LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-15-2009, 04:37 AM   #1
Moody1
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Rep: Reputation: 0
Shell Programming


Hello,
i'm completely new to linux and shell programing
i'm using linux fedora v.8, bash
i want to know how to print argument value depending on other argumet value.
ex. i have two txt files
the first one includes 2 arguments $1, $2 (these values r entered through program)
the second one includes 2 arguments $3, $2 (these values r entered through program)
now through shell program the user will enter $3 value, so i want through this value to print $1 value, any help?


- then i want to know how to consider each word that entered by user as an argument and how to print the third word (as an ex.)
ex. the user will enter this line;
test test1 test2 test3 test4 ....
so how to print the third word?

i hope that my questions are clear

thanks in advance
 
Old 10-15-2009, 04:42 AM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by Moody1 View Post
Hello,
i'm completely new to linux and shell programing
i'm using linux fedora v.8, bash
i want to know how to print argument value depending on other argumet value.
ex. i have two txt files
the first one includes 2 arguments $1, $2 (these values r entered through program)
the second one includes 2 arguments $3, $2 (these values r entered through program)
now through shell program the user will enter $3 value, so i want through this value to print $1 value, any help?


- then i want to know how to consider each word that entered by user as an argument and how to print the third word (as an ex.)
ex. the user will enter this line;
test test1 test2 test3 test4 ....
so how to print the third word?

i hope that my questions are clear

thanks in advance
As to the first part, your request isn't clear enough to fulfill it. Because this is true for us humans, it's certainly true for a computer. Try explaining your wishes in a clear and detailed way.

As to the second part:

Code:
$ x=(test test1 test2 test3 test4)

$ echo ${x[2])
test2
 
Old 10-15-2009, 12:42 PM   #3
Moody1
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Hello,
thanks a lot for ur response, then about the first question it's as follow
i have two txt files;
1- includes the following info. Student_ID , grade class (as one argument).
2- includes the following info. Student_name, student_ID.
now the user will enter student name to get grade and class (as text) to insert values for them.
ex.
{ enter student name;
moody
enter values for grade class;
80 2
}
i hope that it's ok now.

then about the second one how could i deal with that if i don't know how many arguments i have per line?

thanks again
 
Old 10-15-2009, 12:52 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
I smell homework.
 
Old 10-15-2009, 12:59 PM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,541
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

Welcome to LQ!

Just a few links that will aid you;

Linux Documentation Project
Advanced Bash-Scripting Guide
Rute Tutorial & Exposition
Linux Command Guide
LinuxSelfHelp
Getting Started with Linux

The above link and others available from 'Slackware-Links'. More than just SlackwareŽ links!
 
Old 10-15-2009, 07:54 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Provide actual file examples instead of trying to describe them.
 
  


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
shell programming qerf Linux - Newbie 5 11-06-2005 06:28 PM
shell programming shadowsurfer Linux - Newbie 3 09-09-2004 10:40 PM


All times are GMT -5. The time now is 02:55 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration