Can't indent heredoc to match nesting's indent
If there's a "First World Problems" for scripting, this would be it. Mainly asking because I feel like I should know how to get around it if I need to.
I have the following code in a script I'm updating:
if [ $diffLines -eq 1 ]; then
dateLastChanged=$(stat --format '%y' /.bbdata | awk '{print $1" "$2}' | sed 's/\.[0-9]*//g')
mailx -r "Systems and Operations <sysadmin@[redacted].edu>" -s "Warning Stale BB Data" jadavis6@[redacted].edu <<EOI
Last Change: $dateLastChanged
This is an automated warning of stale data for the UNC-G Blackboard Snapshot process.
EOI
else
echo "$diffLines have changed"
fi
I don't mind the sed stuff, or at least can fix that later, my main problem is that I have to add an email notification with this now (that's the change I'm making) I can do it fine with heredoc. I'm using it both as personal preference and it's used in a lot of other scripts so I like to stay with our coding conventions for ease of universal comprehension, even if a lot of it is arbitrary.
The script sends email without issues, but the mailx command is nested within an if statement so I appear to be left with two choices:
Put EOI on a new line and break indentation patterns or
Keep with indentation but use something like an echo statement to get mailx to suck up my email.
I'm open to alternatives to heredoc, but if there's a way to get around this it's my preferred syntax.
If there's a "First World Problems" for scripting, this would be it. Mainly asking because I feel like I should know how to get around it if I need to.
I have the following code in a script I'm updating:
if [ $diffLines -eq 1 ]; then
dateLastChanged=$(stat --format '%y' /.bbdata | awk '{print $1" "$2}' | sed 's/\.[0-9]*//g')
mailx -r "Systems and Operations <sysadmin@[redacted].edu>" -s "Warning Stale BB Data" jadavis6@[redacted].edu <<EOI
Last Change: $dateLastChanged
This is an automated warning of stale data for the UNC-G Blackboard Snapshot process.
EOI
else
echo "$diffLines have changed"
fi
I don't mind the sed stuff, or at least can fix that later, my main problem is that I have to add an email notification with this now (that's the change I'm making) I can do it fine with heredoc. I'm using it both as personal preference and it's used in a lot of other scripts so I like to stay with our coding conventions for ease of universal comprehension, even if a lot of it is arbitrary.
The script sends email without issues, but the mailx command is nested within an if statement so I appear to be left with two choices:
Put EOI on a new line and break indentation patterns or
Keep with indentation but use something like an echo statement to get mailx to suck up my email.
I'm open to alternatives to heredoc, but if there's a way to get around this it's my preferred syntax.
No comments:
Post a Comment