Re: [Dorset] Multiple commands in bash

2015-03-13 Thread Tim Allen

Hi Ralph

On 12/03/15 15:34, Ralph Corderoy wrote:

Hi Tim,


I'd like to run multiple commands in Bash:

patch -m patchfile  hg diff  cd dir  make -s

but for audit purposes I'd like each command in the list to be echoed
as run, even better I'd like the Bash prompt to appear too in front of
each line.


 $ cat tim
 id
 date
 false
 echo not reached
 $
 $ PS1='$ ' bash --norc -ei tim
  A  $ id
 uid=1000(ralph) gid=1000(ralph) 
groups=1000(ralph),4(adm),20(dialout),24(cdrom),30(dip),46(plugdev),100(users),111(lpadmin),119(admin),122(sambashare)
 $ date
 2015-03-12 15:32:23 + Thu
  B  $ false
 $

Note, the `$ ' from A to B are from the bash I've explicitly invoked.
At the end, it returns to my shell.  Ask if there's anything you can't
figure out.



Perfect. -i gives interactive shell so get prompts. -e exits on error.

Cheers

Tim





--
Next meeting:  Bournemouth, Tuesday, 2015-04-07 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR


[Dorset] Multiple commands in bash

2015-03-12 Thread TimA

Hi

I'd like to run multiple commands in Bash:

patch -m patchfile  hg diff  cd dir  make -s

but for audit purposes I'd like each command in the list to be echoed as 
run, even better I'd like the Bash prompt to appear too in front of each 
line.


I know that as an alternative I can put the commands in a script with 
#!/bin/bash -v to get the first requirement.


Cheers

Tim

--
Next meeting:  Bournemouth, Tuesday, 2015-04-07 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR


Re: [Dorset] Multiple commands in bash

2015-03-12 Thread Andrew Montgomery-Hurrell
Not sure if this is what you want, but something like the following might
work. It doesn't do the bash prompt since there is not way of getting the
current prompt output reliably, but if you just want a fake one for display
purposes, you could hard code it into the script. Also, it doesn't check
the exit codes and abort early, as the  would do, but that's easy enough
to add in.

#!/bin/bash

COMMANDS=()
COMMANDS[0]=echo 1
COMMANDS[1]=echo 2
COMMANDS[2]=echo 3

for ((i = 0; i  ${#COMMANDS[@]}; i++)) ; do
echo ${COMMANDS[$i]}
${COMMANDS[$i]}
done

On Thu, 12 Mar 2015 at 14:13 TimA t...@ls83.eclipse.co.uk wrote:

 Hi

 I'd like to run multiple commands in Bash:

 patch -m patchfile  hg diff  cd dir  make -s

 but for audit purposes I'd like each command in the list to be echoed as
 run, even better I'd like the Bash prompt to appear too in front of each
 line.

 I know that as an alternative I can put the commands in a script with
 #!/bin/bash -v to get the first requirement.

 Cheers

 Tim

 --
 Next meeting:  Bournemouth, Tuesday, 2015-04-07 20:00
 Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
 New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
 Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR

--
Next meeting:  Bournemouth, Tuesday, 2015-04-07 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR


Re: [Dorset] Multiple commands in bash

2015-03-12 Thread Ralph Corderoy
Hi Tim,

 I'd like to run multiple commands in Bash:

 patch -m patchfile  hg diff  cd dir  make -s

 but for audit purposes I'd like each command in the list to be echoed
 as run, even better I'd like the Bash prompt to appear too in front of
 each line.

$ cat tim
id
date
false
echo not reached
$
$ PS1='$ ' bash --norc -ei tim
 A  $ id
uid=1000(ralph) gid=1000(ralph) 
groups=1000(ralph),4(adm),20(dialout),24(cdrom),30(dip),46(plugdev),100(users),111(lpadmin),119(admin),122(sambashare)
$ date
2015-03-12 15:32:23 + Thu
 B  $ false
$

Note, the `$ ' from A to B are from the bash I've explicitly invoked.
At the end, it returns to my shell.  Ask if there's anything you can't
figure out.

Cheers, Ralph.

--
Next meeting:  Bournemouth, Tuesday, 2015-04-07 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR