printf command inside a script returns “invalid number”

前端 未结 3 1962
生来不讨喜
生来不讨喜 2020-12-10 02:37

I can\'t get printf to print a variable with the %e descriptor in a bash script. It would just say

#!/bin/bash
a=14.9
printf %e 14.9;

3条回答
  •  無奈伤痛
    2020-12-10 03:05

    I bumped into this error and found this page. In my case, it was 100% pilot error.

    month=2
    printf "%02d" month
    

    it should be

    printf "%02d" "${month}"
    

    or more simply

    printf "%02d" $month
    

提交回复
热议问题