Skip to content

Instantly share code, notes, and snippets.

@rainsunny
Last active August 11, 2017 09:40
Show Gist options
  • Save rainsunny/b9e9ef8e35813f0302b00a31b28c45a6 to your computer and use it in GitHub Desktop.
Save rainsunny/b9e9ef8e35813f0302b00a31b28c45a6 to your computer and use it in GitHub Desktop.
bash snipts
##### get current directory in absolute path
# Add `> /dev/null 2>&1` to eliminate outputs of `cd` in some cases
base_dir="$( cd "$(dirname $0)" > /dev/null 2>&1 && pwd)"
# other options
current_dir=$(pwd) # current working directory
base_dir=$(dirname $0) # in relative path
abs_dir=$(readlink -f $0) # follow link
##### check java version
# When used with [[, the ‘<’ and ‘>’ operators sort lexicographically using the current locale.
java_ver=$( "$JAVA_HOME/bin/java" -version 2>&1 | awk -F '"' '{print $2}' )
echo java version $java_ver
if [[ "$java_ver" > "1.8" ]]; then
echo 1.8 or above
else
echo less than 1.8
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment