Find the answer to your Linux question:
Results 1 to 8 of 8
Hai, I want to display the process id of a daemon along with its name eg: pidof java and the output of my script to be tomcat (pid 123423) is ...
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    5

    Unhappy Bourne shell help in displaying output

    Hai,

    I want to display the process id of a daemon along with its name
    eg: pidof java and the output of my script to be

    tomcat (pid 123423) is running ...
    but if i do like
    echo -n "tomcat ("
    pidof java
    echo -n ) is running

    the output is not obtaining in a single line a newline character is inserted after the command "pidof" . if there is any method to remove the newline after the command "pidof" please help

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Try this:
    Code:
    #!/bin/bash
    
    echo $(echo -n "tomcat ("
    /pidof java
    echo -ne "\b) is running" )
    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Apr 2007
    Posts
    5
    Thank you for your reply
    Unfortunately it is not working saying that

    : command not found
    test: line 6 /pidof: No such file or directory
    ) is running

    Note: i named the file test

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    My mistake. Sorry. Sloppy copying and pasting.

    Remove the slash from just before the pidof. That leaves this:
    Code:
    #!/bin/bash
    
    echo $(echo -n "tomcat ("
    pidof java
    echo -ne "\b) is running" )
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5

  6. #6
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Quote Originally Posted by ghostdog74 View Post
    use printf
    Not sure how printf can be used to remove a newline, care to enlighten us?
    As Bill has said, echo is the tool of choice for converting multi-line output to a single line (and losing excessive whitespace).

  7. #7
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Not sure how printf can be used to remove a newline, care to enlighten us?
    This will work:
    Code:
    #!/bin/bash
    
    printf "tomcat %s is running" $(pidof java)
    --
    Bill

    Old age and treachery will overcome youth and skill.

  8. #8
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Quote Originally Posted by scm View Post
    Not sure how printf can be used to remove a newline, care to enlighten us?
    As Bill has said, echo is the tool of choice for converting multi-line output to a single line (and losing excessive whitespace).
    some variants of Unix support -n and -e which are not standard due to incompatibilities between BSD and System -V. Using printf will make it kinda "portable" too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...