On 4/30/21 2:30 AM, R.Wieser wrote:
> Hello all,
Hi,
> Yesterday I got caught out by a batchfile (which I wrote myself :-)
> ) changing the current directory - I thought I was still in the old
> one ...
Oops
> I decided that I would need to make that 'cd' (its output) visible
> (I've used "@echo off" at the top). I can ofcourse do that in a
> number of ways, but the cleanest way would be if I could allow the
> 'cd' command to display its output.
It's been a while since I've done much in DOS, but I don't think that
'@echo off' changes the /output/ generated by commands.
More specifically, '@echo off' is intended to not show the batch file
/input/ while executing. Read: hide the command to be executed, but not
touch the command's output.
> The question is : is there a prefix that will disable the "echo off"
> for that one line / command ?
Yes and no.
'echo on'
E.g.
@echo off
dir
copy foo bat
echo on
cd \test
@echo off
dir
Remember, the '@' prefix is a per command 'echo off'. Meaning that the
'@' and 'echo off' are two completely independent things.
So ... you can turn echo back on for the cd command and then
subsequently turn it off for the rest of the batch file.
Another trick that I use for short batch files (9 or fewer lines) is:
@dir
@copy foo bat
@echo on
cd \test
@dir
Simply use '@' before each command that you want to not see.
The reason I say 'short' batch files is that '@echo off' is 9 bytes.
Meaning that the above batch file uses fewer bytes by prepending '@' to
thel ines than including an additional line that is '@ech off'. You can
do it for as long a batch file as you want. It just becomes a lot less
efficient and more annoying to add '@' to 30 lines instead of a single
'@echo off'. YMMV.
--
Grant. . . .
unix || die