Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Bash Shell script

I have a script that calls the javac compiler.

echo -e "Compiling..c"
javac Test.java
echo ".Done"


What I wanted to do was to display as follows: (after the compilation succeeds.).

$>Compiling...done.

Second, I wanted to write a script that called another standard script(That came with the product), but like above Iwanted to display
$>Installing....done

The problem is that the standard script emits a lot of messages. I want to supress the messages and display only the above message.

I would greatly appreciate if you can help me with problem.

Thanks.

Comments

  • Jeff P.Jeff P. Member Posts: 196
    echo -n "Compiling.."
    javac Test.java > /dev/null 2>/dev/null
    if [ "$?" = "0" ]
    then
    echo ".Done"
    else
    echo ".Failed"
    done


    : I have a script that calls the javac compiler.
    :
    : echo -e "Compiling..c"
    : javac Test.java
    : echo ".Done"
    :
    :
    : What I wanted to do was to display as follows: (after the compilation succeeds.).
    :
    : $>Compiling...done.
    :
    : Second, I wanted to write a script that called another standard script(That came with the product), but like above Iwanted to display
    : $>Installing....done
    :
    : The problem is that the standard script emits a lot of messages. I want to supress the messages and display only the above message.
    :
    : I would greatly appreciate if you can help me with problem.
    :
    : Thanks.
    :
  • Jeff P.Jeff P. Member Posts: 196
    : echo -n "Compiling.."
    : javac Test.java > /dev/null 2>/dev/null
    : if [ "$?" = "0" ]
    : then
    : echo ".Done"
    : else
    : echo ".Failed"
    : done ###WRONG!###

    Let's try that again...
    [code]
    #!/bin/bash
    echo -n "Compiling.."
    javac Test.java > /dev/null 2>/dev/null
    if [ "$?" = "0" ]
    then
    echo ".Done"
    else
    echo ".Failed"
    fi
    [/code]
  • opensourceopensource Member Posts: 25
    Jeff,

    Thanks for your reply. I tried it and solved some of my scripting problem.

    --
    opensource.


    : : echo -n "Compiling.."
    : : javac Test.java > /dev/null 2>/dev/null
    : : if [ "$?" = "0" ]
    : : then
    : : echo ".Done"
    : : else
    : : echo ".Failed"
    : : done ###WRONG!###
    :
    : Let's try that again...
    : [code]
    : #!/bin/bash
    : echo -n "Compiling.."
    : javac Test.java > /dev/null 2>/dev/null
    : if [ "$?" = "0" ]
    : then
    : echo ".Done"
    : else
    : echo ".Failed"
    : fi
    : [/code]
    :

  • abcabc Member Posts: 443
    less typing: instead of
    [code]
    javac Test.java > /dev/null 2>/dev/null
    [/code]

    do
    [code]
    javac Test.java &>/dev/null
    [/code]

    or
    [code]
    javac Test.java >&/dev/null
    [/code]

    from the bash manual:

    [italic]
    Bash allows both the standard output (file descriptor 1) and the standard error output (file descriptor 2) to be redirected to the file whose name is the expansion of word with this construct.

    There are two formats for redirecting standard output and standard error:

    &>word
    and
    >&word

    Of the two forms, the first is preferred. This is semantically equivalent to

    >word 2>&1

    [/italic]

    2>&1 duplicates the standard error (id 2) as the standard output (id 1). Since the standard output was already set to word, this means that both stdout and stderr are redirected to word. (as a note, if you do 2>&1 > word, you replace stderr with stdout (2 with 1) and then set [italic]only[/italic] stdout to word)
  • Andre YoungAndre Young USAMember Posts: 0

    __ [ http://forcoder.org ] free ebooks and video tutorials about | Ruby JavaScript R MATLAB C# Perl C Java Go Python C++ Assembly PHP Delphi PL/SQL Visual Basic Scratch Swift Objective-C Visual Basic .NET Crystal Alice ML Transact-SQL Logo Kotlin Bash Rust LabVIEW Julia Prolog Clojure Erlang Scala Apex Scheme FoxPro Ada Dart F# Hack Awk Fortran SAS D Lisp ABAP Lua COBOL VBScript | _____

Sign In or Register to comment.