Simple Shell Script does not append to file
The following script does not work:
#!/bin/sh
FILE="/root/.bas开发者_如何学编程hrc"
if [ -f $FILE ]
then
COMMAND="alias ls='ls -la --color=always --human'"
if grep -q "$COMMAND" $FILE
then
echo "NOT CHANGED, Already existing: $COMMAND in $FILE"
else
$FILE << $COMMAND
echo "CHANGED: $COMMAND in $FILE"
fi
else
echo "$FILE does not exist, will not apply changes: $COMMAND"
fi
I get this Error: 32: Syntax error: end of file unexpected (expecting "fi")
I would be very thankful for advice. I am a complete shell newbie, I did some tests but do not understand why this error comes.
Thanks!! Jens
The syntax on line 12 does not append, it starts a heredoc.
echo "$COMMAND" >> "$FILE"
精彩评论