Skip to main content
added 19 characters in body
Source Link
Ohad Eytan
  • 8.5k
  • 1
  • 24
  • 32

If you execute:

printf "%q \n" $latest_version 

you get:

$'1.8.0_101\r' 

and you can see the redundant \r (carriage returns) character.

To fix this add the \r to your tr command and that will work like a charm:

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 "';\r") printf "%s \n" $latest_version 

outputs:

1.8.0_101 

If you execute:

printf "%q \n" $latest_version 

you get:

$'1.8.0_101\r' 

and you can see the redundant \r character.

To fix this add the \r to your tr command and that will work like a charm:

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 "';\r") printf "%s \n" $latest_version 

outputs:

1.8.0_101 

If you execute:

printf "%q \n" $latest_version 

you get:

$'1.8.0_101\r' 

and you can see the redundant \r (carriage returns) character.

To fix this add the \r to your tr command and that will work like a charm:

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 "';\r") printf "%s \n" $latest_version 

outputs:

1.8.0_101 
Source Link
Ohad Eytan
  • 8.5k
  • 1
  • 24
  • 32

If you execute:

printf "%q \n" $latest_version 

you get:

$'1.8.0_101\r' 

and you can see the redundant \r character.

To fix this add the \r to your tr command and that will work like a charm:

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 "';\r") printf "%s \n" $latest_version 

outputs:

1.8.0_101