开发者

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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜