user4654 user4654 - 1 year ago 66
Bash Question

.format equivalent in shell script


, if I have a to create a string with date as suffix, we can do some thing like this:

date = get_todays_date()
name = "automation_results_{}'.format(date)

What is the equivalent of
scripting language?

Answer Source

In bash you can get a date string by invoking date:

name="automation_results_"$(date +%Y_%m_%d) 

with the different options for the format string you can get any date format you prefer.

As @cdarke commented, if you have a recent version of bash you can also do the faster:

name=$(printf "automation_results_%(%Y_%m_%d)T")