LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how execute a command in a list of commands (https://www.linuxquestions.org/questions/programming-9/how-execute-a-command-in-a-list-of-commands-735263/)

bkcreddy17 06-24-2009 08:08 AM

how execute a command in a list of commands
 
Hi i am not expertise at shell script, can anybody clarify my doubt?
I have a file.sh which contains list of commands, say
date
cal
ls
.
.

.
How to execute cal command out of them?
Thanks in an advance......:)

colucix 06-24-2009 08:21 AM

Well, I'd simply type
Code:

cal
What is the reason to retrieve the command from a list, if you already know which command it is? Or have you some criteria to choose cal and not - for example - date or ls? What are you trying to achieve?

bkcreddy17 06-24-2009 09:01 AM

Actually i will execute a long shell script using cron job. It contains mysqladmin command to change the password,say
Code:

mysqladmin -u root -pXXXXX password YYYY
where XXXXX is actual password and YYYY is new password. And i cant remember these complicated passwords. Some times i need to execute this particular command/line in that huge script file. We can get that line by
Code:

grep "mysqladmin - root" file.sh
but how to execute it with grep combination?

colucix 06-24-2009 09:07 AM

It does make sense now. Have you tried this?
Code:

$(grep "mysqladmin -u root" file.sh)
it does command substitution then executes the resulting command line.

bkcreddy17 06-24-2009 09:21 AM

Got it, Thank you colucix.


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