Reputation: 21
#!/bin/bash
if [ "$1" = "boot" ]
then
if [ -f /var/log/boot.log ]
then
echo /var/log/boot.log
elif [ -f /var/log/boot ]
then
echo /var/log/boot
fi
fi
This shows the output:
: command not foundline 8: GetLogfileName.sh: line 15: syntax error
near unexpected token `elif' 'etLogfileName.sh: line 15: `
elif [ -f /var/log/boot ]
What is going wrong here?
Upvotes: 2
Views: 4884
Reputation: 11716
If you are using vi editor, set ":set ff=unix", save the file, and re-execute it.
This file format (ff) set command tells vi to use LF-only line endings when the file is saved.
Upvotes: 2
Reputation: 246847
The garbled error message indicates your file has carriage returns before the newline. Did you edit your script on Windows? Either use your text editor to save the file without carriage returns or run the script through dos2unix
(or perhaps d2u
)
Upvotes: 6