I have a cronjob that executes a small script (few lines) that I am certain can be achieved in a single line.
The functional objective is actually really simple;
cmd var1
The '1' in 'var1' is actually derived from date (day of month) but the snag is when working with 1-9 I require the core numeric (eg: 1, 2, etc not 01, 02, etc) meaning I cannot use 'date +%d' however using %e produces a leading whitespace. So I have addressed that the only simple way I could understand;
echo `date +%e` | tr -s " "
How can I get the output from this (eg: 1, 24, 7) onto the back of var to achieve my final goal and do so in a single command line (so I can stuff it into Cron).
PS: I am a newbie but I tried searching first but could not quite what I am after and I am really hoping you can help.
On some shells, you can do ${!VARNAME} to get the value of the name pointed to by VARNAME instead of the value of VARNAME itself. But this only works in certain shells.
In others you can do math or string operations on the day to get rid of the leading zero.
So, what's your system? What's your shell?
---------- Post updated at 09:48 AM ---------- Previous update was at 09:44 AM ----------
If you have BASH or ksh:
$ echo cmd var$((1$(date +%d) - 100))
cmd var1
$
The trickery with subtracting 100 is necessary because BASH will believe numbers starting with 0 to be octal, not decimal! So we cram a 1 on the front then subtract 100...