You are not logged in.

#1 2008-08-27 19:00:08

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

[SOLVED] Simple Shell Scripting Question - Echo and Execute?

I've got a bash script which has many different commands it executes in a row. Each time the script executes one of the commands, it outputs what it is doing to the screen:

...

echo "cp -r home new"
cp -r home new

echo "mv testfile new/."
mv testfile new/.

...

I am just wondering if there is a function to execute a command and output it at the same time. Something like...

...

echoandexecute("cp -r home new")

echoandexecute("mv testfile new/.")

...

Last edited by tony5429 (2008-08-27 19:59:04)

Offline

#2 2008-08-27 19:09:55

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: [SOLVED] Simple Shell Scripting Question - Echo and Execute?

At the top of your shell script, you presumably have a line like "#!/bin/sh".  Change that to "#!/bin/sh -x".

Offline

#3 2008-08-27 19:19:19

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Simple Shell Scripting Question - Echo and Execute?

Thanks! It works now!

Last edited by tony5429 (2008-08-27 19:22:29)

Offline

#4 2008-08-27 20:55:52

catwell
Member
From: Bretagne, France
Registered: 2008-02-20
Posts: 207
Website

Re: [SOLVED] Simple Shell Scripting Question - Echo and Execute?

Otherwise you can define it yourself:

echoandexecute() {
echo $1
$1
}

echoandexecute "cp -r home new"

Last edited by catwell (2008-08-27 20:57:16)

Offline

Board footer

Powered by FluxBB