LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Modify the script , please help (https://www.linuxquestions.org/questions/linux-newbie-8/modify-the-script-please-help-4175432449/)

ust 10-16-2012 05:29 AM

Modify the script , please help
 
I have a script which called my_script , it can be used to input one parameter ,

$my_script para1

it works fine in the above case

However , if I input more than one parameter like below ,

$my_script para1 para2 para3 ...

it only accept the first one parameter , the para2 , para3 ... is useless in the above case

can advise if I want the script can run all parameter one-by-one , that means run para1 first , then para2 , then para3 .... how can I do ?

druuna 10-16-2012 05:32 AM

Is this a bash, perl, awk, ??? script?

It might also help if post what you've tried this far.

grail 10-16-2012 10:13 AM

So the general idea here is you ask us about a script that we have zero idea about. Ask us to change it as it does not do what you want. And provide absolutely no details about the script itself.

Let me just have a quick look at my crystal ball ... I will get back to you.

TB0ne 10-16-2012 10:56 AM

Quote:

Originally Posted by ust (Post 4806977)
I have a script which called my_script , it can be used to input one parameter ,

$my_script para1

it works fine in the above case However , if I input more than one parameter like below ,

$my_script para1 para2 para3 ...

it only accept the first one parameter , the para2 , para3 ... is useless in the above case can advise if I want the script can run all parameter one-by-one , that means run para1 first , then para2 , then para3 .... how can I do ?

You can do it by writing the script TO do it. This is your script...you get to make it work however you'd like.

Kind of similar to this thread:
https://www.linuxquestions.org/quest...pt-4175423170/

You've been here NINE YEARS, and keep posting questions like this, without showing any effort on your part. Also, you've been given answers to many similar queries in the past, but don't seem to apply them moving forward. For example:

https://www.linuxquestions.org/quest...er-4175413626/
https://www.linuxquestions.org/quest...te-4175413358/
https://www.linuxquestions.org/quest...column-944377/
https://www.linuxquestions.org/quest...script-946113/

As always, we will be happy to HELP you, but you have to show us what you've done/tried, and follow advice given to you. You've been pointed to MANY bash scripting tutorials in the past, ALL of which can answer the question you just asked. Have you referenced ANY of them?

ust 10-16-2012 11:21 AM

thanks reply ,

As the script have password in it , I need to remove it before post it .

But I think it is no need to post the script as I don't want to change anything of my_script , I just would like to have another script to include (run) my_script rather than modify it .

I just would like to run the new script can do my_script para1 , then my_script para2 , then my_script para3 , then .....

Can advise what can I do ?

thanks.

grail 10-16-2012 11:36 AM

Quote:

Can advise what can I do ?
You seem to be still missing the point. We have already advised you many times and pointed out many tutes to help you further.

If you are not willing to show an effort and advise where you are stuck, other than you can't be bothered, I do not see how we can help further.

valdinei 10-16-2012 12:31 PM

One question ust, your script aways have similar action for all params ?

I thought of something:



Code:


####Here all params listed###
params="param1 param2 param3 param4 param5"

#loop for in all params one per time
for param in $params
do
  my_script $param
done
echo "Finished"


Habitual 10-16-2012 01:16 PM

Code:

bang.sh
#!/bin/bash
# Purpose:    Inserts #!/bin/bash into a file and makes it executable
# Usage:    scriptname /path/to/file.sh
# Author:    JJ/Habitual
# Date:    Tue Jul 19, 2011
# Disclaimer:    WTFPL
# Edited:      Tue Oct 16, 2012
# Superseded by "au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod a+x <afile> | endif | endif" in ~/.vimrc
MINPARAMS=1

if [ -n "$1" ]
then
echo "#!/bin/bash" > $1
chmod 700 "$1"
fi

if [ $# -lt "$MINPARAMS" ]
then
  echo Usage: `basename $0` /path/to/script.sh
fi 
exit 0

Specifically documented in the "Positional Parameters" section located here...

HTH and Good Luck!

TB0ne 10-16-2012 03:24 PM

Quote:

Originally Posted by grail (Post 4807345)
You seem to be still missing the point. We have already advised you many times and pointed out many tutes to help you further.
If you are not willing to show an effort and advise where you are stuck, other than you can't be bothered, I do not see how we can help further.

+1....couldn't have said it better.

TB0ne 10-16-2012 03:27 PM

Quote:

Originally Posted by ust (Post 4807334)
thanks reply ,
As the script have password in it , I need to remove it before post it .

That's easily done....just remove the password. It's just one work...why is that a problem?
Quote:

But I think it is no need to post the script as I don't want to change anything of my_script , I just would like to have another script to include (run) my_script rather than modify it .
And honestly, I think you're not posting the script, because you don't have one, and want us to write it for you. Which seems to be a recurring theme.
Quote:

I just would like to run the new script can do my_script para1 , then my_script para2 , then my_script para3 , then .....
Can advise what can I do ?
thanks.
Yes...we will AGAIN advise you to read the MANY scripting tutorials you've been pointed to in the past. Re-read the answers given to you NUMEROUS times over the nine-year span you've been asking, and think about how to APPLY that knowledge.

ust 10-16-2012 06:20 PM

Quote:

Originally Posted by valdinei (Post 4807383)
One question ust, your script aways have similar action for all params ?

I thought of something:



Code:


####Here all params listed###
params="param1 param2 param3 param4 param5"

#loop for in all params one per time
for param in $params
do
  my_script $param
done
echo "Finished"


thanks reply ,

my case is the para name is not the similiar , I do not exactly know the parameter name , so can not be param1 param2 param3 ....

TB0ne 10-16-2012 06:26 PM

So read the tutorials and your other threads...been covered there many times.

And again...post your script and we can help. Otherwise, LEARN...after nine years, this should be something you can do.

valdinei 10-16-2012 06:34 PM

Show your code here... can have more easy for help

ust 10-16-2012 07:38 PM

thanks reply ,

I have modified sth , my script is as below , the program name is .c extension , when run program compile , it only compile the first one parameter ( the first program input program name ) , I just would like to compile all programs when input multiple program name .

#vi my_script
"
PROG=/home/ora_tmp/TMP$$.c
"
program_compile $PROG
"
"

program_compile is a script for compiling program .

TB0ne 10-17-2012 11:13 AM

Quote:

Originally Posted by ust (Post 4807682)
thanks reply ,
I have modified sth , my script is as below , the program name is .c extension , when run program compile , it only compile the first one parameter ( the first program input program name ) , I just would like to compile all programs when input multiple program name .

#vi my_script
"
PROG=/home/ora_tmp/TMP$$.c
"
program_compile $PROG
"
"
program_compile is a script for compiling program .

Since you seem to be missing/not understanding things:
  • This is NOT your whole script
  • Yes, we DO understand what you WANT to do...restating it doesn't add anything new.
  • Look at the answers you have been given many, MANY times before.
Again, you have been here for NINE YEARS. You've been given MANY scripting lessons and pointed to many scripting tutorials. Why can't you apply what you've been told, or learn from it???


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