LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-21-2008, 04:49 AM   #1
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Rep: Reputation: 15
scripting question


Hi all,

I want to execute a small script and echo the commands that are inside.

Right now I am doing it as following:

echo cd /home/jurian/test
echo ./run

cd /home/jurian/test
./run

This is working fine, however, everytime I edit the code I need to replace it in 2 places. Is there any better way to solve this?

Thanx in advance,

Jurrian
 
Old 10-21-2008, 04:55 AM   #2
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
hmm, found out that it is working, but that it first executes the cript and then echo's what it have done, is there a way to make it first echo wat it does and then execute it? That way any eventual errors will be more logic to read

Thanx in advance,

Jurrian
 
Old 10-21-2008, 04:58 AM   #3
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 593

Rep: Reputation: 30
Jurrian,

If you want to execute the commands
Code:
 cd /home/jurian/test
./run
Then echo is not needed. In case, if you want to display them only, using echo,

Code:
echo -e "cd /home/jurian/test"
echo "./run"
Cheers
 
Old 10-21-2008, 05:01 AM   #4
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 593

Rep: Reputation: 30
You can try the following :

Code:
echo -e "cd /home/jurian/test"
cd /home/jurian/test
echo -e "./run"
./run
To have a time difference , in between display and execute add sleep

Code:
echo -e "cd /home/jurian/test"
sleep 5
cd /home/jurian/test
echo -e "./run"
sleep 5
./run

Last edited by ZAMO; 10-21-2008 at 05:05 AM. Reason: echo -e "./run"
 
Old 10-21-2008, 05:01 AM   #5
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
Actually, I want to run and display them, while the output should first contain the command and after that the output of the command..

Thanx for your reply,

Jurrian
 
Old 10-21-2008, 05:15 AM   #6
Jurrian
Member
 
Registered: Sep 2008
Posts: 58

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by ZAMO View Post
You can try the following :

Code:
echo -e "cd /home/jurian/test"
cd /home/jurian/test
echo -e "./run"
./run
To have a time difference , in between display and execute add sleep

Code:
echo -e "cd /home/jurian/test"
sleep 5
cd /home/jurian/test
echo -e "./run"
sleep 5
./run
Well, the point is, I still need to type the commands twice, so if I change the directory, I need to change it at 2 places, at the echo command and at the execute command. I wondered if there was any way to prevent this.

Thanx, Jurrian
 
  


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
Scripting Question stlouis Programming 7 01-24-2008 05:01 PM
Scripting question msandford Linux - Newbie 4 09-05-2005 10:23 AM
Scripting Question... Darklight451 Linux - Newbie 3 09-23-2004 05:03 PM
Scripting question.... Darklight451 Linux - Newbie 2 09-13-2004 11:29 PM
Scripting question sujte Linux - General 2 05-24-2004 04:52 PM


All times are GMT -5. The time now is 10:05 PM.

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