1

I have a script that creates a hash of a file, writes it to vars.txt and then checks that variable next time the script is run to determine if the file has changed.

Here is the script and vars.txt (pastebin)

When I run the script I call the variable with source /path/to/file

This now gives me the following error when the file is parsed:

/opt/scripts/AutoCommit/vars.txt: line 2: etchttpdconf_dvhost.conf=925ec4d7bd0dc94c3710bcf5fb2c80f422806bb5  /etc/httpd/conf.d/vhost.conf: No such file or directory

On top of that, when the file changes sed is now not replacing the line but adding an additional line underneath. It had not done this in the past.

You get a file that ends up like this. Until recently this did not happen so I suspect they are both caused by the same issue.

Here is a stripped down version of the script, where I believe the problem may be.

  • 1
    your . isnt getting handled, i think? does the bash ${///} var stuff treat dots like sed does? because a . dot to sed has to be escaped \. to literally mean dot, else it means any single character. – mikeserv Oct 8 '15 at 11:59
1

change your

fileVarName="${fileVarName/./_}"

to do all dots

fileVarName="${fileVarName//./_}"
2

The . (dot) is not a valid character in a variable name, as defined in your vars.txt:

gitinstalled="1"
etchttpdconf_dvhost.conf="925ec4d7bd0dc94c3710bcf5fb2c80f422806bb5  /etc/httpd/conf.d/vhost.conf"
etchttpdconf_dvhost.conf="925ec4d7bd0dc94c3710bcf5fb2c80f422806bb5  /etc/httpd/conf.d/vhost.conf"
  • i didnt look very hard at it, but it appeared that the main script is supposed to be replacing . dots with _ underscores or something. – mikeserv Oct 8 '15 at 12:00
  • 1
    @mikeserv I too stopped looking after I realised that the script was the full thing rather than a cut-down version that illustrated the problem. – roaima Oct 8 '15 at 12:09
  • well, i dunno, i think the problem might be in the 40 echo lines somewhere, maybe, too – mikeserv Oct 8 '15 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.