Maybe it is a silly question, but I\'m trying to redirect the exit of \"java -version\" command to a file or variable but it doesn\'t work.
Server = Linux CentOS 6<
java -version
writes to stderr (fileno 2), not stdout (fileno 1). You can redirect stderr to a file:
java -version 2> test.txt
# cat test.txt
# java version "1.7.0_25"
# OpenJDK Runtime Environment
# [...]
Or you can redirect stderr to stdout:
java_check=$(java -version 2>&1)
# echo "$java_check"
# java version "1.7.0_25" OpenJDK Runtime Environment [...]