Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
変数がある場合
month=02これに month=`expr $month + 1` のように 1 を追加すると、次のようになりますが 、これをどうしmonth=3たいですか?month=03
month=02
month=3
month=03
追加しても
month=`expr $month + 01`
うまくいきません。
使用printf:
printf
$ month=1 $ printf "%02d" $month 01
このアプローチは、monthが 2 桁の数字の場合に機能します。
month
$ month=11 $ printf "%02d" $month 11
[ と言って変数をインクリメントすることもできますlet month++。]
let month++