LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell Programming (https://www.linuxquestions.org/questions/linux-newbie-8/shell-programming-762027/)

Moody1 10-15-2009 03:37 AM

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

lutusp 10-15-2009 03:42 AM

Quote:

Originally Posted by Moody1 (Post 3719989)
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


Moody1 10-15-2009 11:42 AM

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

catkin 10-15-2009 11:52 AM

I smell homework.

onebuck 10-15-2009 11:59 AM

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 :hattip:

The above link and others available from 'Slackware-Links'. More than just SlackwareŽ links!

chrism01 10-15-2009 06:54 PM

Provide actual file examples instead of trying to describe them.


All times are GMT -5. The time now is 01:59 AM.