set echo off and on

Hi
I have written a bash script to capture the output of jmap.
The command i execute is jmap -heap <pid>
This gives details of memory usage of the process with <pid>.
Now jmap not only gives this info but also prints couple more lines, which i am not interested in. Here are the lines that I am not able to capture and I dont want these lines to be echoed

Attaching to process ID 20850, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 17.1-b03

I tried to set echo off before executing jmap and set echo on after this statement, but of no use.

set echo off works fine, but it does not turn on later.
Please suggest.

Here is my script

#!/bin/bash

psdetails=$(ps -ef | grep "$1" | grep -v "grep" | grep -v "heapDataExtractor")
# Get the pid
pid=$(echo $psdetails | awk '{split($0, a," "); print a[2] }')

set echo off

$JAVA_HOME/bin/jmap -heap $pid  > jmapRawData.txt

let headerCount=0

set echo on

while read line
do
#do some processing and echo the output
done < jmapRawData.txt

All commands are 1 input and 2 outputs :

  • the standart output (stdout)
  • the standart error output (stderr)

In the console input is the keyboard and outputs are the screen.

So this line :

$JAVA_HOME/bin/jmap -heap $pid  > jmapRawData.txt

writes stdout into the file jmapRawData.txt and shows the stderr. So you only need to put stderr to a null file :

$JAVA_HOME/bin/jmap -heap $pid  > jmapRawData.txt 2> /dev/null

2> /dev/null
Thanks a lot, that did my job

It does. In bash, set sth sth will assign positional parameters:

$ set echo off
$ echo $*
echo off