skip to Main Content

My code is :

#!/bin/bash

strversion=`apache2ctl -v | awk '{print $3}' | sed  's/(Debian)//g;s/Server//g;s/built//g;s/2022-06-09T04:26:43//g'`

echo ${strversion%}
exit 0

i get this:

Apache/2.4.54

but i will have to look

Apache version 2.4.54

2

Answers


  1. Chosen as BEST ANSWER

    Try the following:

    strversion=$(apache2ctl -v | head -1 | awk -F '[ /]' '{printf "%s version %s", $3, $4}')


  2. That’s because the variable expansion is not quoted. An unquoted variable is subject to Word Splitting (and Filename Expansion)

    echo "Apache2 - ${strversion%')'}"
    # ...^...........................^
    

    See also Security implications of forgetting to quote a variable in bash/POSIX shells

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search