shell/bash


Read a template file and replace placeholder

script-template.txt

#!/bin/bash
echo "--TIMESTAMP--"

gen-script.sh

#!/bin/bash
# Get variables
timestamp=`date`

# Replace placeholder
content=`cat ./script-template.txt`
content=`echo "${content/--TIMESTAMP--/$timestamp}"`

# Generate a script
echo "$content" > startup.sh
chmod +x startup.sh

 

Leave a comment

Your email address will not be published. Required fields are marked *