how to receive files sent as a parameter
as $1 $2 represent first and second argument..
for example- in a shell script... ./commfile file1 file2 file3 now in commfile i want to receive files by running a loop...like for (i=1;i<$#;i++) do cat ${i} //help me here echo do u want to proceed read req if($req=y||$req=Y) //it also not works then continue else exit fi done |
Edit: Nevermind, Eric wins below.
|
Hello and Welcome to LinuxQuestions,
If you want to go through parameters you added on a commandline without knowing how many there will be you can use $@ Quote:
Code:
Kind regards, Eric |
thanx!
|
Hi,
You're welcome. If you consider your question/problem solved then please mark it as such using the Thread Tools. Kind regards, Eric |
@ericTRA
sorry for ur inconvenience...but can u plz tell me why it is not working..... for (( i=1; i<$#;i++)) do cat ${i} // or cat ${$i} //or cat $"$i" . . . done |
Hello,
No inconvenience at all here. To what are you referring when you say it's not working? To the code example I provided (that does work)? Or do you want explanation on how it is yours is not working? Kind regards, Eric |
Quote:
Cheers, Josh Edit - I am just helping you because the way you are doing it CAN work, but it is more complicated; Why do something more complicated and ugly, when you can use the basics to achieve the same task? Also, please spell out your words, instead of using "plz" and "u." Thank you for understanding. |
yes.. that is working..but i want to know
how to do that in this way..the way i am doing.... |
Hello,
For a complete understanding you should start by reading the links I pointed to in order to learn Bash from the beginning. For example you are not using = correctly (look at the difference between your code and mine). Apart from that you're not quoting y or Y (look at the Bash Guide for Beginners on quotation and what it's used for. Kind regards, Eric |
All times are GMT -5. The time now is 07:11 AM. |