I use printf in /bin/bash (OS X standard GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15) Copyright (C) 2007 Free Software Foundation, Inc.
#!/bin/bash latest_version=\ $((curl -s http://java.com/en/download/installed8.jsp 2>/dev/null || wget -q -O - http://java.com/en/download/installed8.jsp) | grep 'latest8' |sed -E "s/.*= //" |tr -d "';") echo $latest_version printf "%s \n" $latest_version I want to get a string "1.8.0_102" (as of 2016/7/24)
This shows
#echo 1.8.0_101 #printf 8.0_101 I want to make the string in red and the script will be run in both OS X and linux, so I do not want to use echo.
Why can't I get 1.8.0_101 by printf?
Further more what is wrong with this below?
printf "Get the latest Java \033[1;31m %s \033[m from Oracle.\n" $latest_version It also does not work...
I have a hint... when I put
latest_version=1.8.0_101 then it works.
so the variable input to latest_version by $() is working wrong?
latest_version=$((curl -s http://java.com/en/download/installed8.jsp 2>/dev/null || wget -q -O - http://java.com/en/download/installed8.jsp) | grep latest8 | cut -f 2 -d\')grep,sed,trpipe should be a singlesedcommand:sed -n "/latest8/{s/.*= //;s/[';\r]//g;p}"sed -n "/latest8/s/.*'\([^']*\)'.*/\1/p"