LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-24-2009, 07:08 AM   #1
bkcreddy17
Member
 
Registered: Feb 2008
Location: India-Hyderabad
Distribution: RHEL and Fedora
Posts: 171

Rep: Reputation: 15
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......
 
Old 06-24-2009, 07:21 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980
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?
 
Old 06-24-2009, 08:01 AM   #3
bkcreddy17
Member
 
Registered: Feb 2008
Location: India-Hyderabad
Distribution: RHEL and Fedora
Posts: 171

Original Poster
Rep: Reputation: 15
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?
 
Old 06-24-2009, 08:07 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980Reputation: 1980
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.
 
Old 06-24-2009, 08:21 AM   #5
bkcreddy17
Member
 
Registered: Feb 2008
Location: India-Hyderabad
Distribution: RHEL and Fedora
Posts: 171

Original Poster
Rep: Reputation: 15
Got it, Thank you colucix.
 
  


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
Execute a command , reboot and then execute another command ganeshp@moris.org Linux - Newbie 3 12-03-2008 12:51 AM
bash: execute a semicolon separated list of commands within string Meson Linux - General 3 10-01-2008 11:25 PM
How to execute commands within a subshell opened by another command? plin Programming 3 02-11-2008 08:19 AM
Execute different commands at startup lucazorzi Linux - General 7 11-02-2007 07:46 AM
Using FTP to execute command line commands remotely steve_2010 Solaris / OpenSolaris 4 02-13-2004 08:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:42 AM.

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